1
0
Fork 0
mirror of synced 2024-09-18 18:40:24 +12:00

Add headers validator benchmark

This commit is contained in:
Matej Bačo 2024-08-20 08:47:50 +00:00
parent cdef3e0cde
commit 69977138da
4 changed files with 1403 additions and 9 deletions

View file

@ -13,7 +13,8 @@
"scripts": {
"test": "vendor/bin/phpunit",
"lint": "vendor/bin/pint --test",
"format": "vendor/bin/pint"
"format": "vendor/bin/pint",
"bench": "vendor/bin/phpbench run --report=benchmark"
},
"autoload": {
"psr-4": {
@ -86,7 +87,8 @@
"phpunit/phpunit": "9.5.20",
"swoole/ide-helper": "5.1.2",
"textalk/websocket": "1.5.7",
"laravel/pint": "^1.14"
"laravel/pint": "^1.14",
"phpbench/phpbench": "^1.2"
},
"provide": {
"ext-phpiredis": "*"

1330
composer.lock generated

File diff suppressed because it is too large Load diff

6
phpbench.json Normal file
View 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"
}

View 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);
}
}
}