Skip to content

Instantly share code, notes, and snippets.

@hidek
Created September 15, 2009 10:41
Show Gist options
  • Select an option

  • Save hidek/187219 to your computer and use it in GitHub Desktop.

Select an option

Save hidek/187219 to your computer and use it in GitHub Desktop.
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