Add headers validator benchmark
This commit is contained in:
parent
cdef3e0cde
commit
69977138da
4 changed files with 1403 additions and 9 deletions
|
@ -13,7 +13,8 @@
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "vendor/bin/phpunit",
|
"test": "vendor/bin/phpunit",
|
||||||
"lint": "vendor/bin/pint --test",
|
"lint": "vendor/bin/pint --test",
|
||||||
"format": "vendor/bin/pint"
|
"format": "vendor/bin/pint",
|
||||||
|
"bench": "vendor/bin/phpbench run --report=benchmark"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
|
@ -86,7 +87,8 @@
|
||||||
"phpunit/phpunit": "9.5.20",
|
"phpunit/phpunit": "9.5.20",
|
||||||
"swoole/ide-helper": "5.1.2",
|
"swoole/ide-helper": "5.1.2",
|
||||||
"textalk/websocket": "1.5.7",
|
"textalk/websocket": "1.5.7",
|
||||||
"laravel/pint": "^1.14"
|
"laravel/pint": "^1.14",
|
||||||
|
"phpbench/phpbench": "^1.2"
|
||||||
},
|
},
|
||||||
"provide": {
|
"provide": {
|
||||||
"ext-phpiredis": "*"
|
"ext-phpiredis": "*"
|
||||||
|
|
1330
composer.lock
generated
1330
composer.lock
generated
File diff suppressed because it is too large
Load diff
6
phpbench.json
Normal file
6
phpbench.json
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
{
|
||||||
|
"$schema":"vendor/phpbench/phpbench/phpbench.schema.json",
|
||||||
|
"runner.bootstrap": "vendor/autoload.php",
|
||||||
|
"runner.path": "tests",
|
||||||
|
"runner.file_pattern": "*Bench.php"
|
||||||
|
}
|
70
tests/unit/Functions/Validator/HeadersBench.php
Normal file
70
tests/unit/Functions/Validator/HeadersBench.php
Normal file
|
@ -0,0 +1,70 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Unit\Functions\Validator;
|
||||||
|
|
||||||
|
use Appwrite\Functions\Validator\Headers;
|
||||||
|
use PhpBench\Attributes\AfterMethods;
|
||||||
|
use PhpBench\Attributes\Assert;
|
||||||
|
use PhpBench\Attributes\BeforeMethods;
|
||||||
|
use PhpBench\Attributes\Iterations;
|
||||||
|
use PhpBench\Attributes\ParamProviders;
|
||||||
|
|
||||||
|
final class HeadersBench
|
||||||
|
{
|
||||||
|
private Headers $validator;
|
||||||
|
|
||||||
|
public function tearDown(): void {}
|
||||||
|
|
||||||
|
public function prepare(): void
|
||||||
|
{
|
||||||
|
$this->validator = new Headers();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function providers(): iterable
|
||||||
|
{
|
||||||
|
yield 'empty' => [ 'value' => [] ];
|
||||||
|
|
||||||
|
$value = [];
|
||||||
|
for($i = 0; $i < 10; $i++) {
|
||||||
|
$value[bin2hex(random_bytes(8))] = bin2hex(random_bytes(8));
|
||||||
|
}
|
||||||
|
yield 'xxs' => [ 'value' => $value ];
|
||||||
|
|
||||||
|
$value = [];
|
||||||
|
for($i = 0; $i < 100; $i++) {
|
||||||
|
$value[bin2hex(random_bytes(8))] = bin2hex(random_bytes(8));
|
||||||
|
}
|
||||||
|
yield 'xs' => [ 'value' => $value ];
|
||||||
|
|
||||||
|
$value = [];
|
||||||
|
for($i = 0; $i < 1000; $i++) {
|
||||||
|
$value[bin2hex(random_bytes(8))] = bin2hex(random_bytes(8));
|
||||||
|
}
|
||||||
|
yield 'sm' => [ 'value' => $value ];
|
||||||
|
|
||||||
|
$value = [];
|
||||||
|
for($i = 0; $i < 10000; $i++) {
|
||||||
|
$value[bin2hex(random_bytes(16))] = bin2hex(random_bytes(16));
|
||||||
|
}
|
||||||
|
yield 'md' => [ 'value' => $value ];
|
||||||
|
|
||||||
|
$value = [];
|
||||||
|
for($i = 0; $i < 100000; $i++) {
|
||||||
|
$value[bin2hex(random_bytes(16))] = bin2hex(random_bytes(16));
|
||||||
|
}
|
||||||
|
yield 'lg' => [ 'value' => $value ];
|
||||||
|
}
|
||||||
|
|
||||||
|
#[BeforeMethods('prepare')]
|
||||||
|
#[AfterMethods('tearDown')]
|
||||||
|
#[ParamProviders('providers')]
|
||||||
|
#[Iterations(50)]
|
||||||
|
#[Assert('mode(variant.time.avg) < 500 ms')]
|
||||||
|
public function benchHeadersValidator(array $data): void
|
||||||
|
{
|
||||||
|
$assertion = $this->validator->isValid($data['value']);
|
||||||
|
if(!$assertion) {
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue