mirror of
https://github.com/dannyvankooten/AltoRouter.git
synced 2025-07-31 13:40:16 +02:00
update benchmark
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user