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' ) {
51 if ( eval 'require CGI::Simple' ) {
52 $benchmarks->{'CGI::Simple'} = sub {
54 $content->seek( 0, SEEK_SET )
57 STDIN->fdopen( $content->fileno, 'r' );
59 CGI::Simple::_reset_globals();
61 my $cgi = CGI::Simple->new;
65 if ( eval 'require APR::Request' ) {
70 require APR::Request::CGI;
71 require APR::Request::Param;
73 $benchmarks->{'APR::Request'} = sub {
75 $content->seek( 0, SEEK_SET )
78 STDIN->fdopen( $content->fileno, 'r' );
80 my $pool = APR::Pool->new;
81 my $apr = APR::Request::CGI->handle($pool);
83 if ( my $table = $apr->param ) {
84 $table->do( sub { 1 } );
87 if ( my $body = $apr->body ) {
88 $body->param_class('APR::Request::Param');
89 $body->uploads($pool)->do( sub { 1 } );
94 my @benchmarks = @ARGV ? @ARGV : qw[ t/data/benchmark/001
96 t/data/benchmark/003 ];
98 foreach my $benchmark ( @benchmarks ) {
100 $headers = LoadFile("$FindBin::Bin/../$benchmark-headers.yml");
101 $content = IO::File->new( "$FindBin::Bin/../$benchmark-content.dat", O_RDONLY )
107 CONTENT_LENGTH => $headers->{'Content-Length'},
108 CONTENT_TYPE => $headers->{'Content-Type'},
110 REQUEST_METHOD => 'POST'
113 printf( "Content-Type : %s\n", $headers->{'Content-Type'} =~ m/^([^;]+)/ );
114 printf( "Content-Length : %s\n", $headers->{'Content-Length'} );
115 printf( "Benchmark : %s\n", $headers->{'Benchmark'} ) if $headers->{'Benchmark'};
118 timethese( -1, $benchmarks );
120 printf( "%s\n", "-" x 80 ) if @benchmarks > 1;