packages/sql-semantics-postgres/bench/AnalyzeBench.php
1<?php
2
3declare(strict_types=1);
4
5namespace Bench;
6
7use PhpBench\Attributes as Benchmark;
8use SqlSemantics\Platform\PostgreSql\Semantics;
9
10/**
11 * Measures analyzing a PostgreSQL statement into its semantic model and back to SQL.
12 */
13final class AnalyzeBench
14{
15 private Semantics $semantics;
16
17 /**
18 * Loads the profile and the parser before measurement.
19 */
20 public function setUp(): void
21 {
22 $this->semantics = new Semantics();
23 }
24
25 /**
26 * Analyzes a selection with typed constants, names and comparisons.
27 */
28 #[Benchmark\BeforeMethods('setUp')]
29 #[Benchmark\Revs(50)]
30 #[Benchmark\Iterations(5)]
31 public function benchAnalyze(): void
32 {
33 $this->semantics->analyze("SELECT a, x.b AS total, 0x1F, 1.50e3, timestamp(3) with time zone '2024-01-01' FROM app.t AS x WHERE a >= \$1");
34 }
35}
36