From 87d93b68403331a95e4ba2c21569048303b94ec1 Mon Sep 17 00:00:00 2001 From: Danny van Kooten Date: Thu, 7 Feb 2019 09:16:23 +0100 Subject: [PATCH] update benchmark --- tests/benchmark.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/tests/benchmark.php b/tests/benchmark.php index 310fcfb..99b2584 100644 --- a/tests/benchmark.php +++ b/tests/benchmark.php @@ -60,11 +60,11 @@ $router = new AltoRouter(); // map requests $start = microtime(true); foreach($requests as $r) { - $router->map($r['method'], $r['url'], function(){}); + $router->map($r['method'], $r['url'], ''); } $end = microtime(true); -$map_time = $end - $start; -echo "Map time: " . number_format($map_time, 6). ' seconds' . PHP_EOL; +$map_time = ($end - $start) * 1000; +echo sprintf( 'Map time: %.2f ms', $map_time ) . PHP_EOL; // pick random route to match @@ -74,20 +74,20 @@ $r = $requests[array_rand($requests)]; $start = microtime(true); $router->match($r['url'], $r['method']); $end = microtime(true); -$match_time_known_route = $end - $start; -echo "Match time (known route): " . number_format($match_time_known_route, 6). ' seconds' . PHP_EOL; +$match_time_known_route = ($end - $start) * 1000; +echo sprintf( 'Match time (known route): %.2f ms', $match_time_known_route ) . PHP_EOL; // match unexisting route $start = microtime(true); $router->match('/55-foo-bar', 'GET'); $end = microtime(true); -$match_time_unknown_route = $end - $start; -echo "Match time (unknown route): " . number_format($match_time_unknown_route, 6). ' seconds' . PHP_EOL; +$match_time_unknown_route = ($end - $start) * 1000; +echo sprintf( 'Match time (unknown route): %.2f ms', $match_time_unknown_route ) . PHP_EOL; // print totals -echo "Total time: " . number_format(($map_time + $match_time_known_route + $match_time_unknown_route), 6). ' seconds' . PHP_EOL; -echo "Memory usage: " . round( memory_get_usage() / 1024 ) . 'KB' . PHP_EOL; -echo "Peak memory usage: " . round( memory_get_peak_usage( true ) / 1024 ) . 'KB' . PHP_EOL; +echo sprintf('Total time: %.2f seconds', ($map_time + $match_time_known_route + $match_time_unknown_route)) . PHP_EOL; +echo sprintf('Memory usage: %d KB', round( memory_get_usage() / 1024 )) . PHP_EOL; +echo sprintf('Peak memory usage: %d KB', round( memory_get_peak_usage( true ) / 1024 )) . PHP_EOL;