Created
September 15, 2009 10:41
-
-
Save hidek/187219 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
| package Plack::Benchmark; | |
| use strict; | |
| use warnings; | |
| use Plack::Loader; | |
| use Test::TCP; | |
| sub run_benchmark { | |
| my ($class, $impl, $handler, $args) = @_; | |
| my $con = $args->{concurrency} || 10; | |
| my $num = $args->{requests} || 100; | |
| my $cmd = "ab -c $con -n $num -k http://127.0.0.1"; | |
| my $res; | |
| test_tcp( | |
| client => sub { | |
| my $port = shift; | |
| $res = `$cmd:$port/`; | |
| }, | |
| server => sub { | |
| my $port = shift; | |
| my $impl = Plack::Loader->load($impl, port => $port); | |
| $impl->run($handler); | |
| $impl->run_loop if $impl->can('run_loop'); | |
| } | |
| ); | |
| $res =~ /Requests per second:\s*([\d\.]*)/; | |
| return $1; | |
| } | |
| 1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment