Skip to content

Commit d6e1a8a

Browse files
committed
restore bench tests
1 parent 4b1a177 commit d6e1a8a

File tree

2 files changed

+54
-1
lines changed

2 files changed

+54
-1
lines changed

composer.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@
5050
"phpstan/phpstan-deprecation-rules": "^1.2.1",
5151
"phpunit/phpunit": "^10.5.38 || ^11.4.4",
5252
"symfony/var-dumper": "^6.4.15 || ^v7.2.0",
53-
"bakame/aide-base32": "dev-main"
53+
"bakame/aide-base32": "dev-main",
54+
"phpbench/phpbench": "^1.3"
5455
},
5556
"autoload": {
5657
"psr-4": {
@@ -63,6 +64,7 @@
6364
}
6465
},
6566
"scripts": {
67+
"benchmark": "phpbench run --report=default",
6668
"phpcs": "php-cs-fixer fix --dry-run --diff -vvv --allow-risky=yes --ansi",
6769
"phpcs:fix": "php-cs-fixer fix -vvv --allow-risky=yes --ansi",
6870
"phpstan": "phpstan analyse -c phpstan.neon --ansi --memory-limit 192M",
@@ -75,6 +77,7 @@
7577
]
7678
},
7779
"scripts-descriptions": {
80+
"benchmark": "Runs parser benchmark",
7881
"phpstan": "Runs complete codebase static analysis",
7982
"phpunit": "Runs unit and functional testing",
8083
"phpcs": "Runs coding style testing",

tests/ParserBench.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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

Comments
 (0)