diff --git a/tests/tools.php b/tests/tools.php index e70346f..33baa94 100644 --- a/tests/tools.php +++ b/tests/tools.php @@ -106,13 +106,18 @@ function runIterations(int $iterations, $r, array $routes) { $interval = $iterations / 10; for ($i = 0; $i < $iterations; $i++) { // 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); 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); } - 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 the average time per request