appwrite/tests/unit/Functions/Validator/HeadersBench.php

61 lines
1.5 KiB
PHP
Raw Normal View History

2024-08-20 08:47:50 +00:00
<?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;
2024-08-20 09:21:29 +00:00
public function tearDown(): void
{
}
2024-08-20 08:47:50 +00:00
public function prepare(): void
{
$this->validator = new Headers();
}
public function providers(): iterable
{
yield 'empty' => [ 'value' => [] ];
$value = [];
2024-09-05 02:25:11 +00:00
for ($i = 0; $i < 10; $i++) {
2024-08-20 08:47:50 +00:00
$value[bin2hex(random_bytes(8))] = bin2hex(random_bytes(8));
}
2024-08-20 09:19:31 +00:00
yield 'items_10-size_320' => [ 'value' => $value ];
2024-08-20 08:47:50 +00:00
$value = [];
2024-09-05 02:25:11 +00:00
for ($i = 0; $i < 100; $i++) {
2024-08-20 08:47:50 +00:00
$value[bin2hex(random_bytes(8))] = bin2hex(random_bytes(8));
}
2024-08-20 09:19:31 +00:00
yield 'items_100-size_3200' => [ 'value' => $value ];
2024-08-20 08:47:50 +00:00
$value = [];
2024-09-05 02:25:11 +00:00
for ($i = 0; $i < 100; $i++) {
2024-08-20 09:24:19 +00:00
$value[bin2hex(random_bytes(32))] = bin2hex(random_bytes(32));
2024-08-20 08:47:50 +00:00
}
2024-08-20 09:24:19 +00:00
yield 'items_100-size_12800' => [ 'value' => $value ];
2024-08-20 08:47:50 +00:00
}
#[BeforeMethods('prepare')]
#[AfterMethods('tearDown')]
#[ParamProviders('providers')]
#[Iterations(50)]
2024-08-20 09:19:31 +00:00
#[Assert('mode(variant.time.avg) < 1 ms')]
2024-08-20 08:47:50 +00:00
public function benchHeadersValidator(array $data): void
{
$assertion = $this->validator->isValid($data['value']);
2024-09-05 02:25:11 +00:00
if (!$assertion) {
2024-08-20 08:47:50 +00:00
exit(1);
}
}
}