Skip to content
This repository has been archived by the owner on Jun 2, 2018. It is now read-only.

FastRoute benchmark is not precise...? #15

Open
tsvetelintsonev opened this issue Feb 23, 2016 · 0 comments
Open

FastRoute benchmark is not precise...? #15

tsvetelintsonev opened this issue Feb 23, 2016 · 0 comments

Comments

@tsvetelintsonev
Copy link

Hi there. First of all thanks for the benchmark. I was impressed by good performance of FastRoute and decided to look at worst-case-tests.php
I have played with it a bit and thought that it will be good idea to measure the time it takes by FastRoute to find a given route directly inside "setupFastRoute" function.

-----This is changes that I've made -----

function setupFastRoute(Benchmark $benchmark, $routes, $args)
{
$argString = implode('/', array_map(function ($i) { return "{arg$i}"; }, range(1, $args)));
$str = $firstStr = $lastStr = '';
$router = \FastRoute\simpleDispatcher(function ($router) use ($routes, $argString, &$lastStr) {
for ($i = 0; $i < $routes; $i++) {
list ($pre, $post) = getRandomParts();
$str = '/' . $pre . '/' . $argString . '/' . $post;
if (0 === $i) {
$firstStr = str_replace(array('{', '}'), '', $str);
}
$lastStr = str_replace(array('{', '}'), '', $str);
$router->addRoute('GET', $str, 'handler' . $i);
}
});
$start = microtime(true);
$route = $router->dispatch('GET', $lastStr);
echo microtime(true) - $start ;
}

and I am getting a surprisingly slow result of 0.0069520473480225
Do you think that something is wrong with FastRoute's benchmark?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

1 participant