Last active
August 29, 2015 14:01
-
-
Save karupanerura/5575388dfb37d9650a63 to your computer and use it in GitHub Desktop.
Router::R3 benchmark
This file contains 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
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
use utf8; | |
use 5.018002; | |
use autodie; | |
use Benchmark qw(:all); | |
use Router::Boom; | |
use Router::Boom::Method; | |
use Router::Simple; | |
use Router::R3; | |
my $router_boom = do { | |
my $router = Router::Boom->new(); | |
$router->add('/', 'Root'); | |
$router->add('/entrylist', 'EntryList'); | |
$router->add("/$_", "$_") for 'a'..'c'; | |
$router->add('/:user', 'User#index'); | |
$router->add('/:user/:year/', 'UserBlog#year_archive'); | |
$router->add('/:user/:year/:month/', 'UserBlog#month_archive'); | |
$router; | |
}; | |
my $router_boom_method = do { | |
my $router = Router::Boom::Method->new(); | |
$router->add(undef, '/', 'Root'); | |
$router->add(undef, '/entrylist', 'EntryList'); | |
$router->add(undef, "/$_", "$_") for 'a'..'c'; | |
$router->add(undef, '/:user', 'User#index'); | |
$router->add(undef, '/:user/:year/', 'UserBlog#year_archive'); | |
$router->add(undef, '/:user/:year/:month/', 'UserBlog#month_archive'); | |
$router; | |
}; | |
my $router_simple = do { | |
my $router = Router::Simple->new(); | |
$router->connect('/', 'Root'); | |
$router->connect('/entrylist', 'EntryList'); | |
$router->connect("/$_", "$_") for 'a'..'c'; | |
$router->connect('/:user', 'User#index'); | |
$router->connect('/:user/:year/', 'UserBlog#year_archive'); | |
$router->connect('/:user/:year/:month/', 'UserBlog#month_archive'); | |
$router; | |
}; | |
my $router_r3 = Router::R3->new( | |
'/' => 'Root', | |
'/entrylist' => 'EntryList', | |
(map { ("/$_" => "$_") } 'a'..'c'), | |
'/:user' => 'User#index', | |
'/:user/:year/' => 'UserBlog#year_archive', | |
'/:user/:year/:month/' => 'UserBlog#month_archive', | |
); | |
cmpthese( | |
-1, { | |
'Router::Simple' => sub { $router_simple->match('/dankogai/2013/02') }, | |
'Router::Boom' => sub { $router_boom->match('/dankogai/2013/02') }, | |
'Router::Boom::Method' => sub { $router_boom_method->match('GET', '/dankogai/2013/02') }, | |
'Router::R3' => sub { $router_r3->match('/dankogai/2013/02') }, | |
} | |
); |
This file contains 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
Rate Router::Simple Router::Boom::Method Router::Boom Router::R3 | |
Router::Simple 85418/s -- -65% -72% -98% | |
Router::Boom::Method 240941/s 182% -- -21% -94% | |
Router::Boom 303675/s 256% 26% -- -93% | |
Router::R3 4287316/s 4919% 1679% 1312% -- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment