packages/sql-fixture/bench/SchemaParsingBench.php
1<?php
2
3declare(strict_types=1);
4
5namespace Bench;
6
7use PhpBench\Attributes as Bench;
8use SqlFixture\Platform\MySql\MySqlSchemaParser;
9use SqlFixture\Platform\PostgreSql\PostgreSqlSchemaParser;
10use SqlFixture\Platform\Sqlite\SqliteSchemaParser;
11
12/**
13 * Measures uncached schema parsing with equivalent declarations in each dialect.
14 */
15#[Bench\Groups(['schema'])]
16#[Bench\Revs(5000)]
17final class SchemaParsingBench
18{
19 /**
20 * Parses MySQL DDL without a provider cache.
21 */
22 public function benchMySql(): void
23 {
24 (new MySqlSchemaParser())->parse('CREATE TABLE items (id INT PRIMARY KEY AUTO_INCREMENT, name VARCHAR(80) NOT NULL, price DECIMAL(8, 2), active BOOLEAN DEFAULT TRUE)');
25 }
26
27 /**
28 * Parses PostgreSQL DDL without a provider cache.
29 */
30 public function benchPostgreSql(): void
31 {
32 (new PostgreSqlSchemaParser())->parse('CREATE TABLE items (id SERIAL PRIMARY KEY, name VARCHAR(80) NOT NULL, price NUMERIC(8, 2), active BOOLEAN DEFAULT TRUE)');
33 }
34
35 /**
36 * Parses SQLite DDL without a provider cache.
37 */
38 public function benchSqlite(): void
39 {
40 (new SqliteSchemaParser())->parse('CREATE TABLE items (id INTEGER PRIMARY KEY AUTOINCREMENT, name VARCHAR(80) NOT NULL, price DECIMAL(8, 2), active BOOLEAN DEFAULT TRUE)');
41 }
42}
43