1
0
mirror of https://github.com/dannyvankooten/AltoRouter.git synced 2025-07-31 13:40:16 +02:00

update benchmark

This commit is contained in:
Danny van Kooten
2019-02-07 09:16:23 +01:00
parent 9bdfc55eb3
commit 87d93b6840

View File

@@ -60,11 +60,11 @@ $router = new AltoRouter();
// map requests // map requests
$start = microtime(true); $start = microtime(true);
foreach($requests as $r) { foreach($requests as $r) {
$router->map($r['method'], $r['url'], function(){}); $router->map($r['method'], $r['url'], '');
} }
$end = microtime(true); $end = microtime(true);
$map_time = $end - $start; $map_time = ($end - $start) * 1000;
echo "Map time: " . number_format($map_time, 6). ' seconds' . PHP_EOL; echo sprintf( 'Map time: %.2f ms', $map_time ) . PHP_EOL;
// pick random route to match // pick random route to match
@@ -74,20 +74,20 @@ $r = $requests[array_rand($requests)];
$start = microtime(true); $start = microtime(true);
$router->match($r['url'], $r['method']); $router->match($r['url'], $r['method']);
$end = microtime(true); $end = microtime(true);
$match_time_known_route = $end - $start; $match_time_known_route = ($end - $start) * 1000;
echo "Match time (known route): " . number_format($match_time_known_route, 6). ' seconds' . PHP_EOL; echo sprintf( 'Match time (known route): %.2f ms', $match_time_known_route ) . PHP_EOL;
// match unexisting route // match unexisting route
$start = microtime(true); $start = microtime(true);
$router->match('/55-foo-bar', 'GET'); $router->match('/55-foo-bar', 'GET');
$end = microtime(true); $end = microtime(true);
$match_time_unknown_route = $end - $start; $match_time_unknown_route = ($end - $start) * 1000;
echo "Match time (unknown route): " . number_format($match_time_unknown_route, 6). ' seconds' . PHP_EOL; echo sprintf( 'Match time (unknown route): %.2f ms', $match_time_unknown_route ) . PHP_EOL;
// print totals // print totals
echo "Total time: " . number_format(($map_time + $match_time_known_route + $match_time_unknown_route), 6). ' seconds' . PHP_EOL; echo sprintf('Total time: %.2f seconds', ($map_time + $match_time_known_route + $match_time_unknown_route)) . PHP_EOL;
echo "Memory usage: " . round( memory_get_usage() / 1024 ) . 'KB' . PHP_EOL; echo sprintf('Memory usage: %d KB', round( memory_get_usage() / 1024 )) . PHP_EOL;
echo "Peak memory usage: " . round( memory_get_peak_usage( true ) / 1024 ) . 'KB' . PHP_EOL; echo sprintf('Peak memory usage: %d KB', round( memory_get_peak_usage( true ) / 1024 )) . PHP_EOL;