|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace Bakame\Http\StructuredFields; |
| 6 | + |
| 7 | +use PhpBench\Attributes as Bench; |
| 8 | + |
| 9 | +final class ParserBench |
| 10 | +{ |
| 11 | + private readonly Parser $parser; |
| 12 | + |
| 13 | + public function __construct() |
| 14 | + { |
| 15 | + $this->parser = Parser::new(); |
| 16 | + } |
| 17 | + |
| 18 | + #[Bench\Iterations(4)] |
| 19 | + #[Bench\OutputTimeUnit('seconds')] |
| 20 | + #[Bench\Assert('mode(variant.mem.peak) < 2097152'), Bench\Assert('mode(variant.time.avg) < 10000000')] |
| 21 | + public function benchParsingAList(): void |
| 22 | + { |
| 23 | + $httpValue = '("lang" "en-US"); expires=@1623233894; samesite=Strict; secure'; |
| 24 | + for ($i = 0; $i < 100_000; $i++) { |
| 25 | + $this->parser->parseList($httpValue); |
| 26 | + } |
| 27 | + } |
| 28 | + |
| 29 | + #[Bench\Iterations(4)] |
| 30 | + #[Bench\OutputTimeUnit('seconds')] |
| 31 | + #[Bench\Assert('mode(variant.mem.peak) < 2097152'), Bench\Assert('mode(variant.time.avg) < 10000000')] |
| 32 | + public function benchParsingAnItem(): void |
| 33 | + { |
| 34 | + $httpValue = '"lang"; expires=@1623233894; samesite=Strict; secure'; |
| 35 | + for ($i = 0; $i < 100_000; $i++) { |
| 36 | + $this->parser->parseItem($httpValue); |
| 37 | + } |
| 38 | + } |
| 39 | + |
| 40 | + #[Bench\Iterations(4)] |
| 41 | + #[Bench\OutputTimeUnit('seconds')] |
| 42 | + #[Bench\Assert('mode(variant.mem.peak) < 2097152'), Bench\Assert('mode(variant.time.avg) < 10000000')] |
| 43 | + public function benchParsingAnDictionary(): void |
| 44 | + { |
| 45 | + $httpValue = 'lang="en-US"; samesite=Strict; secure, type=42.0; expires=@1623233894'; |
| 46 | + for ($i = 0; $i < 100_000; $i++) { |
| 47 | + $this->parser->parseDictionary($httpValue); |
| 48 | + } |
| 49 | + } |
| 50 | +} |
0 commit comments