9 use lib "$FindBin::Bin/../lib";
11 use Benchmark qw[cmpthese timethese];
16 use IO::File qw[O_RDONLY SEEK_SET];
17 use YAML qw[LoadFile];
19 my ( $headers, $content, $message );
24 $content->seek( 0, SEEK_SET )
27 STDIN->fdopen( $content->fileno, 'r' );
29 CGI::_reset_globals();
35 $content->seek( 0, SEEK_SET )
38 my $body = HTTP::Body->new( $headers->{'Content-Type'},
39 $headers->{'Content-Length'} );
41 while ( $content->read( my $buffer, 4096 ) ) {
45 unless ( $body->state eq 'done' ) {
49 'HTTP::Body Complete' => sub {
51 my $body = HTTP::Body->new( $headers->{'Content-Type'},
52 $headers->{'Content-Length'} );
56 unless ( $body->state eq 'done' ) {
62 if ( eval 'require CGI::Simple' ) {
63 $benchmarks->{'CGI::Simple'} = sub {
65 $content->seek( 0, SEEK_SET )
68 STDIN->fdopen( $content->fileno, 'r' );
70 CGI::Simple::_reset_globals();
72 my $cgi = CGI::Simple->new;
76 my @benchmarks = @ARGV ? @ARGV : qw[ t/data/benchmark/001
78 t/data/benchmark/003 ];
80 foreach my $benchmark ( @benchmarks ) {
82 $headers = LoadFile("$FindBin::Bin/../$benchmark-headers.yml");
83 $content = IO::File->new( "$FindBin::Bin/../$benchmark-content.dat", O_RDONLY )
88 $message = do{ local $/; <$content> };
91 CONTENT_LENGTH => $headers->{'Content-Length'},
92 CONTENT_TYPE => $headers->{'Content-Type'},
94 REQUEST_METHOD => 'POST'
97 printf( "Content-Type : %s\n", $headers->{'Content-Type'} =~ m/^([^;]+)/ );
98 printf( "Content-Length : %s\n", $headers->{'Content-Length'} );
99 printf( "Benchmark : %s\n", $headers->{'Benchmark'} ) if $headers->{'Benchmark'};
102 cmpthese( -1, $benchmarks );
104 printf( "%s\n", "-" x 80 ) if @benchmarks > 1;