File tree Expand file tree Collapse file tree 5 files changed +54
-2
lines changed Expand file tree Collapse file tree 5 files changed +54
-2
lines changed Original file line number Diff line number Diff line change 12
12
/phpunit.xml export-ignore
13
13
/** /* Test.php export-ignore
14
14
/** /Test ** export-ignore
15
+ /** /* Bench.php export-ignore
Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ All Notable changes to `bakame/http-strucured-fields` will be documented in this
20
20
### Fixed
21
21
22
22
- Test suite migrated to PHPUnit 10
23
+ - Adding Benchmark test with PHPBench
23
24
- Improve Collection immutability with method changes
24
25
- ** [ BC Break] ** ` ParameterAccess ` interface signature updated to use the ` Value ` interface instead of the ` Item ` implementation.
25
26
- ** [ BC Break] ** ` MemberList::remove ` , ` MemberOrderedMap::remove ` and ` MemberOrderedMap::keys ` methods are moved to their parent interface.
Original file line number Diff line number Diff line change 34
34
"phpstan/phpstan-strict-rules" : " ^1.5.0" ,
35
35
"phpstan/phpstan-phpunit" : " ^1.3.10" ,
36
36
"phpstan/phpstan-deprecation-rules" : " ^1.1.2" ,
37
- "phpunit/phpunit" : " ^10.0.15"
37
+ "phpunit/phpunit" : " ^10.0.15" ,
38
+ "phpbench/phpbench" : " ^1.2"
38
39
},
39
40
"autoload" : {
40
41
"psr-4" : {
46
47
]
47
48
},
48
49
"scripts" : {
50
+ "benchmark" : " phpbench run --report=default" ,
49
51
"phpcs" : " PHP_CS_FIXER_IGNORE_ENV=1 php-cs-fixer fix --dry-run --diff -vvv --allow-risky=yes --ansi" ,
50
52
"phpcs:fix" : " php-cs-fixer fix -vvv --allow-risky=yes --ansi" ,
51
53
"phpstan" : " phpstan analyse -c phpstan.neon --ansi --xdebug --memory-limit 192M" ,
52
54
"phpunit" : " XDEBUG_MODE=coverage phpunit --coverage-text" ,
53
55
"test" : [
54
56
" @phpunit" ,
55
57
" @phpstan" ,
56
- " @phpcs"
58
+ " @phpcs" ,
59
+ " @benchmark"
57
60
]
58
61
},
59
62
"scripts-descriptions" : {
Original file line number Diff line number Diff line change
1
+ {
2
+ "$schema" : " vendor/phpbench/phpbench/phpbench.schema.json" ,
3
+ "runner.bootstrap" : " vendor/autoload.php" ,
4
+ "runner.path" : [" src" ],
5
+ "runner.file_pattern" : " *Bench.php" ,
6
+ "runner.php_disable_ini" : true
7
+ }
Original file line number Diff line number Diff line change
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
+ #[Bench \OutputTimeUnit('seconds ' )]
12
+ #[Bench \Assert('mode(variant.mem.peak) < 2097152 ' ), Bench \Assert('mode(variant.time.avg) < 10000000 ' )]
13
+ public function benchParsingAListFormAnHTTPHeaderValue (): void
14
+ {
15
+ $ httpValue = '("lang" "en-US"); expires=@1623233894; samesite=Strict; secure ' ;
16
+ for ($ i = 0 ; $ i < 100_000 ; $ i ++) {
17
+ Parser::parseList ($ httpValue );
18
+ }
19
+ }
20
+
21
+ #[Bench \OutputTimeUnit('seconds ' )]
22
+ #[Bench \Assert('mode(variant.mem.peak) < 2097152 ' ), Bench \Assert('mode(variant.time.avg) < 10000000 ' )]
23
+ public function benchParsingAnItemFormAnHTTPHeaderValue (): void
24
+ {
25
+ $ httpValue = '"lang"; expires=@1623233894; samesite=Strict; secure ' ;
26
+ for ($ i = 0 ; $ i < 100_000 ; $ i ++) {
27
+ Item::fromHttpValue ($ httpValue );
28
+ }
29
+ }
30
+
31
+ #[Bench \OutputTimeUnit('seconds ' )]
32
+ #[Bench \Assert('mode(variant.mem.peak) < 2097152 ' ), Bench \Assert('mode(variant.time.avg) < 10000000 ' )]
33
+ public function benchParsingAnDictionaryFormAnHTTPHeaderValue (): void
34
+ {
35
+ $ httpValue = 'lang="en-US", type=42.0; expires=@1623233894; samesite=Strict; secure ' ;
36
+ for ($ i = 0 ; $ i < 100_000 ; $ i ++) {
37
+ Parser::parseDictionary ($ httpValue );
38
+ }
39
+ }
40
+ }
You can’t perform that action at this time.
0 commit comments