|
| 1 | +<?php declare(strict_types = 1); |
| 2 | + |
| 3 | +namespace PHPStan\PhpDocParser\Benchmarks; |
| 4 | + |
| 5 | +use PHPStan\PhpDocParser\Lexer\Lexer; |
| 6 | +use PHPStan\PhpDocParser\Parser\ConstExprParser; |
| 7 | +use PHPStan\PhpDocParser\Parser\PhpDocParser; |
| 8 | +use PHPStan\PhpDocParser\Parser\TokenIterator; |
| 9 | +use PHPStan\PhpDocParser\Parser\TypeParser; |
| 10 | +use PHPStan\PhpDocParser\ParserConfig; |
| 11 | +use Tally\Attribute\Before; |
| 12 | +use Tally\Attribute\Warmup; |
| 13 | + |
| 14 | +/** |
| 15 | + * Parsing the PHPDocs of a config/reference.php that Symfony 7.4 generates, as PHPStan does: |
| 16 | + * one large array shape with many generics and constant types. 1427af4 made it about twice as |
| 17 | + * quick by computing the token offsets once, 3fcdcf0 twice as quick again by not walking to |
| 18 | + * the end of the PHPDoc for every generic. |
| 19 | + */ |
| 20 | +final class SymfonyConfigReferenceBench |
| 21 | +{ |
| 22 | + |
| 23 | + private Lexer $lexer; |
| 24 | + |
| 25 | + private PhpDocParser $phpDocParser; |
| 26 | + |
| 27 | + /** @var list<string> */ |
| 28 | + private array $phpDocs; |
| 29 | + |
| 30 | + #[Before] |
| 31 | + public function prepare(): void |
| 32 | + { |
| 33 | + $config = new ParserConfig(['lines' => true]); |
| 34 | + $constExprParser = new ConstExprParser($config); |
| 35 | + $this->lexer = new Lexer($config); |
| 36 | + $this->phpDocParser = new PhpDocParser($config, new TypeParser($config, $constExprParser), $constExprParser); |
| 37 | + $this->phpDocs = require __DIR__ . '/data/symfony-config-reference.php'; |
| 38 | + } |
| 39 | + |
| 40 | + #[Warmup(1)] |
| 41 | + public function benchParse(): void |
| 42 | + { |
| 43 | + foreach ($this->phpDocs as $phpDoc) { |
| 44 | + $this->phpDocParser->parse(new TokenIterator($this->lexer->tokenize($phpDoc))); |
| 45 | + } |
| 46 | + } |
| 47 | + |
| 48 | +} |
0 commit comments