Debian Codegraph @

author/benchmark/byown.pl

raw
1 use strict;
2 use warnings;
3 use autodie;
4 use Benchmark ':all';
5 use Starman;
6 use LWP::UserAgent;
7 use WWW::Curl::Easy 4.14;
8 use Furl::HTTP;
9 use Child;
10 use Test::TCP qw/empty_port/;
11 use Plack::Loader;
12 use Config;
13 use HTTP::Lite;
14
15 printf "Perl/%vd on %s\n", $^V, $Config{archname};
16 printf "Furl/$Furl::VERSION, LWP/$LWP::VERSION, WWW::Curl/$WWW::Curl::VERSION, HTTP::Lite/$HTTP::Lite::VERSION, libcurl[@{[ WWW::Curl::Easy::version() ]}]\n";
17
18 my $port = empty_port();
19
20 my $ua = LWP::UserAgent->new(parse_head => 0, keep_alive => 1);
21 my $curl = WWW::Curl::Easy->new();
22 my $furl = Furl::HTTP->new(parse_header => 0);
23 my $url = "http://127.0.0.1:$port/foo/bar";
24
25 my $child = Child->new(
26 sub {
27 Plack::Loader->load( 'Starman', port => $port )
28 ->run(
29 sub { [ 200, ['Content-Length' => length('Hi')], ['Hi'] ] } );
30 }
31 );
32 my $proc = $child->start();
33
34 cmpthese(
35 -1, {
36 lwp => sub {
37 my $res = $ua->get($url);
38 },
39 curl => sub {
40 my @headers;
41 $curl->setopt(CURLOPT_URL, $url);
42 $curl->setopt(CURLOPT_HTTPGET, 1);
43 $curl->setopt(CURLOPT_HEADER, 0);
44 $curl->setopt(CURLOPT_NOPROGRESS, 1);
45 $curl->setopt(CURLOPT_HEADERFUNCTION, sub {
46 push @headers, @_;
47 length($_[0]);
48 });
49 my $content = '';
50 $curl->setopt(CURLOPT_WRITEDATA, \$content);
51 $curl->perform();
52 my $code = $curl->getinfo(CURLINFO_HTTP_CODE);
53 },
54 furl => sub {
55 $furl->request(method => 'GET', url => $url);
56 },
57 },
58 );
59
60 $proc->kill('TERM');
61