packages/ztd-query-mysql/bench/ParserBench.php

1<?php
2
3declare(strict_types=1);
4
5namespace Bench;
6
7use PhpBench\Attributes as Bench;
8use ZtdQuery\Platform\MySql\Sql\MySqlParser;
9
10/**
11 * Implements the Parser Bench contract for MySQL.
12 */
13final class ParserBench
14{
15    private MySqlParser $parser;
16
17    private string $selectSql = 'SELECT u.id, u.name, o.status FROM users u JOIN orders o ON o.user_id = u.id WHERE u.id = 1';
18
19    private string $insertSql = "INSERT INTO users (id, name, email) VALUES (1, 'Alice', 'alice@example.com')";
20
21    /**
22     * Set Up for the supplied MySQL input.
23     */
24    public function setUp(): void
25    {
26        $this->parser = new MySqlParser();
27    }
28
29    /**
30     * Bench Parse Select for the supplied MySQL input.
31     */
32    #[Bench\BeforeMethods('setUp')]
33    #[Bench\Revs(2000)]
34    public function benchParseSelect(): void
35    {
36        $this->parser->parse($this->selectSql);
37    }
38
39    /**
40     * Bench Parse Insert for the supplied MySQL input.
41     */
42    #[Bench\BeforeMethods('setUp')]
43    #[Bench\Revs(2000)]
44    public function benchParseInsert(): void
45    {
46        $this->parser->parse($this->insertSql);
47    }
48}
49