mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
Add headers validator benchmark
This commit is contained in:
+4
-2
@@ -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": "*"
|
||||||
|
|||||||
Generated
+1323
-7
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"$schema":"vendor/phpbench/phpbench/phpbench.schema.json",
|
||||||
|
"runner.bootstrap": "vendor/autoload.php",
|
||||||
|
"runner.path": "tests",
|
||||||
|
"runner.file_pattern": "*Bench.php"
|
||||||
|
}
|
||||||
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user