Created
April 20, 2009 16:51
-
-
Save masaki/98614 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/perl | |
use strict; | |
use warnings; | |
use Benchmark qw(:hireswallclock timethese); | |
use Test::MockObject; | |
use FindBin::libs; | |
use HTTP::Router::Declare; | |
my $router = router { | |
match '/' => to { controller => 'Root', action => 'index' }; | |
match '/account/login', { method => 'POST' } => to { controller => 'Account', action => 'login' }; | |
match '/archives/{year}', { year => qr/^\d{4}$/ } => to { controller => 'Archives', action => 'by_year' }; | |
resources 'Users'; | |
resource 'Admin'; | |
}; | |
sub request { | |
my $r = Test::MockObject->new; | |
my %p = @_; | |
while (my ($k, $v) = each %p) { | |
$r->set_always($k, $v); | |
} | |
$r; | |
} | |
my $path_request = request(path => '/'); | |
my $conditions_request = request(path => '/account/login', method => 'POST'); | |
my $validate_request = request(path => '/archives/2009'); | |
my $resources_request = request(path => '/users/new', method => 'GET'); | |
my $resource_request = request(path => '/admin/edit', method => 'GET'); | |
timethese(10000, { | |
path => sub { $router->match($path_request) }, | |
conditions => sub { $router->match($conditions_request) }, | |
validate => sub { $router->match($validate_request) }, | |
resources => sub { $router->match($resources_request) }, | |
resource => sub { $router->match($resource_request) }, | |
}); |
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
# commit 4747c0743d7ea75e86ee15d0eed38773cf952875 | |
Benchmark: timing 10000 iterations of conditions, path, resource, resources, validate... | |
conditions: 2.01825 wallclock secs ( 1.98 usr + 0.01 sys = 1.99 CPU) @ 5025.13/s (n=10000) | |
path: 1.36359 wallclock secs ( 1.34 usr + 0.01 sys = 1.35 CPU) @ 7407.41/s (n=10000) | |
resource: 20.1460 wallclock secs (19.74 usr + 0.17 sys = 19.91 CPU) @ 502.26/s (n=10000) | |
resources: 6.44921 wallclock secs ( 6.32 usr + 0.05 sys = 6.37 CPU) @ 1569.86/s (n=10000) | |
validate: 3.28694 wallclock secs ( 3.23 usr + 0.02 sys = 3.25 CPU) @ 3076.92/s (n=10000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment