forked from PHP/Router
Add random params to tests, update error formatting
This commit is contained in:
parent
c85d488e43
commit
5277acfe39
|
@ -106,13 +106,18 @@ function runIterations(int $iterations, $r, array $routes) {
|
||||||
$interval = $iterations / 10;
|
$interval = $iterations / 10;
|
||||||
for ($i = 0; $i < $iterations; $i++) {
|
for ($i = 0; $i < $iterations; $i++) {
|
||||||
// pick a random route from the array
|
// pick a random route from the array
|
||||||
[$method, $uri] = $routes[array_rand($routes)];
|
[$method, $path] = $routes[array_rand($routes)];
|
||||||
|
// replace all :params/ with random values
|
||||||
|
$uri = preg_replace_callback('/:(\w+)/', function($matches) {
|
||||||
|
return rand(1, 100);
|
||||||
|
}, $path);
|
||||||
|
$start2 = microtime(true);
|
||||||
$res = $r->lookup($method, $uri);
|
$res = $r->lookup($method, $uri);
|
||||||
if ($res === 404 || $res === 405) {
|
if ($res === 404 || $res === 405) {
|
||||||
echo Color::red("Failed to handle request for $uri - $res\n");
|
echo Color::red("Failed to handle request.\n$method $res\n"."├─ URI: $uri\n├─ Path: $path\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
if ($i !== 0 && $i % ($interval) === 0) echoMemoryAndTime($i, $start);
|
if ($i !== 0 && $i % ($interval) === 0) echoMemoryAndTime($i, $start2);
|
||||||
}
|
}
|
||||||
echo "Time: " . Color::cyan(number_format(microtime(true) - $start, 10) . " s\n");
|
echo "Time: " . Color::cyan(number_format(microtime(true) - $start, 10) . " s\n");
|
||||||
// echo the average time per request
|
// echo the average time per request
|
||||||
|
|
Loading…
Reference in New Issue
Block a user