Created
February 20, 2016 04:48
-
-
Save alexrohleder/bc302708653b68d1b053 to your computer and use it in GitHub Desktop.
Profile Comparison between Codeburner Router and FastRoute. The comparison results can be found in https://blackfire.io/profiles/compare/b861281b-b6d4-4015-b25b-fd9399e789ba...914e81ac-0898-4633-81b1-6c9f1bbfab69/graph?settings%5Bdimension%5D=wt&settings%5Bdisplay%5D=landscape&settings%5BtabPane%5D=nodes&selected=&callname=main()
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
include "vendor/autoload.php"; | |
include "routes.php"; | |
$collector = new Codeburner\Router\Collector(); | |
$matcher = new Codeburner\Router\Matcher($collector); | |
foreach ($routes as $path) { | |
$collector->get($path, function () use ($path) { | |
echo "Matched route with path: $path, passed ", count(func_get_args()), " args."; | |
}); | |
} | |
$route = $matcher->match("get", $routes[count($routes) - 1]); | |
$route->call(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"require": { | |
"nikic/fast-route": "^0.7.0", | |
"codeburner/router": "^2.0" | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
include "vendor/autoload.php"; | |
include "routes.php"; | |
$mapper = new FastRoute\RouteCollector(new FastRoute\RouteParser\Std, new FastRoute\DataGenerator\GroupCountBased); | |
foreach ($routes as $path) { | |
$mapper->addRoute("GET", $path, function () use ($path) { | |
echo "Matched route with path: $path, passed ", count(func_get_args()), " args."; | |
}); | |
} | |
$matcher = new FastRoute\Dispatcher\GroupCountBased($mapper->getData()); | |
$route = $matcher->dispatch("GET", $routes[count($routes) - 1]); | |
call_user_func_array($route[1], $route[2]); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* This file is used to generate the routes for both routers. | |
*/ | |
$routes = []; | |
//** for 100 routes with args variating on 1 to 9 | |
foreach (range(1, 10) as $i) { | |
foreach (range(1, 10) as $j) { | |
$uri = '/' . $i; | |
foreach (range(1, $j) as $k) { | |
$uri .= '/{arg' . $k . '}'; | |
} | |
$routes[] = $uri; | |
} | |
} | |
/**/ | |
/** for 100 routes with 9 args like nikic benchmark | |
$args = implode('/', array_map(function ($i) { | |
return "{arg$i}"; | |
}, range(1, 9))); | |
for ($i = 0, $str = 'a'; $i < 100; $i++, $str++) { | |
$routes[] = '/' . $str . '/' . $args; | |
} | |
**/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment