9 use lib "$FindBin::Bin/../lib";
10 use lib "$FindBin::Bin/../t/lib";
12 use Benchmark qw[cmpthese timethese];
17 use IO::File qw[O_RDONLY SEEK_SET];
18 use PAML qw[LoadFile];
20 my ( $headers, $content, $message );
25 $content->seek( 0, SEEK_SET )
28 STDIN->fdopen( $content->fileno, 'r' );
30 CGI::_reset_globals();
36 $content->seek( 0, SEEK_SET )
39 my $body = HTTP::Body->new( $headers->{'Content-Type'},
40 $headers->{'Content-Length'} );
42 while ( $content->read( my $buffer, 4096 ) ) {
46 unless ( $body->state eq 'done' ) {
52 if ( eval 'require CGI::Simple' ) {
53 $benchmarks->{'CGI::Simple'} = sub {
55 $content->seek( 0, SEEK_SET )
58 STDIN->fdopen( $content->fileno, 'r' );
60 CGI::Simple::_reset_globals();
62 my $cgi = CGI::Simple->new;
66 if ( eval 'require APR::Request' ) {
71 require APR::Request::CGI;
72 require APR::Request::Param;
74 $benchmarks->{'APR::Request'} = sub {
76 $content->seek( 0, SEEK_SET )
79 STDIN->fdopen( $content->fileno, 'r' );
81 my $pool = APR::Pool->new;
82 my $apr = APR::Request::CGI->handle($pool);
84 if ( my $table = $apr->param ) {
85 $table->do( sub { 1 } );
88 if ( my $body = $apr->body ) {
89 $body->param_class('APR::Request::Param');
90 $body->uploads($pool)->do( sub { 1 } );
95 my @benchmarks = @ARGV ? @ARGV : qw[ t/data/benchmark/001
97 t/data/benchmark/003 ];
99 foreach my $benchmark ( @benchmarks ) {
101 $headers = LoadFile("$FindBin::Bin/../$benchmark-headers.pml");
102 $content = IO::File->new( "$FindBin::Bin/../$benchmark-content.dat", O_RDONLY )
108 CONTENT_LENGTH => $headers->{'Content-Length'},
109 CONTENT_TYPE => $headers->{'Content-Type'},
111 REQUEST_METHOD => 'POST'
114 printf( "Content-Type : %s\n", $headers->{'Content-Type'} =~ m/^([^;]+)/ );
115 printf( "Content-Length : %s\n", $headers->{'Content-Length'} );
116 printf( "Benchmark : %s\n", $headers->{'Benchmark'} ) if $headers->{'Benchmark'};
119 timethese( -1, $benchmarks );
121 printf( "%s\n", "-" x 80 ) if @benchmarks > 1;