Created
May 10, 2010 03:09
-
-
Save kazeburo/395632 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 | |
se strict; | |
se warnings; | |
se AnyEvent; | |
se AnyEvent::Curl; | |
se HTTP::Request; | |
se Time::HiRes qw//; | |
use Coro; | |
my $ua = AnyEvent::Curl->new(max_parallel=>1000); | |
my $gcv = $ua->start; | |
my $start = Time::HiRes::time; | |
for my $i ( 1..10 ) { | |
async { | |
my $req = HTTP::Request->new( GET => 'http://localhost:5000/' ); | |
$req->header( 'Connection', 'close'); | |
my $cv = $ua->add($req, undef ); | |
my $res = $cv->recv; | |
printf "[%s] %s %s\n", $i, Time::HiRes::time - $start ,${$res->{body}}; | |
} | |
} | |
$gcv->recv; | |
printf "end: %s \n", Time::HiRes::time - $start; |
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
# connection: close | |
% perl test.pl | |
[1] 0.0187339782714844 foobar | |
[2] 0.0190548896789551 foobar | |
[3] 0.0191869735717773 foobar | |
[5] 0.0192928314208984 foobar | |
[6] 0.0193979740142822 foobar | |
[7] 0.0194888114929199 foobar | |
[8] 0.0195808410644531 foobar | |
[9] 0.0196847915649414 foobar | |
[10] 0.0197799205780029 foobar | |
[4] 0.0201108455657959 foobar | |
end: 0.0202629566192627 | |
# connection: closeなし | |
% perl test.pl | |
[1] 1.02325892448425 foobar | |
[2] 1.02350902557373 foobar | |
[3] 1.02369689941406 foobar | |
[4] 1.02388906478882 foobar | |
[5] 1.02397704124451 foobar | |
[6] 1.02409887313843 foobar | |
[7] 1.02421498298645 foobar | |
[8] 1.02432894706726 foobar | |
[9] 1.02446603775024 foobar | |
[10] 1.02451992034912 foobar | |
end: 1.02455997467041 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment