Added APR::Request to benchmark
Christian Hansen [Tue, 18 Oct 2005 16:59:12 +0000 (16:59 +0000)]
lib/HTTP/Body/MultiPart.pm
scripts/benchmark.pl

index e11f12d..45569c3 100644 (file)
@@ -273,7 +273,7 @@ sub handler {
 
         if ($filename) {
 
-            my $fh = File::Temp->new; #( UNLINK => 0 );
+            my $fh = File::Temp->new( UNLINK => 0 );
 
             $part->{fh}       = $fh;
             $part->{tempname} = $fh->filename;
index 170f048..16f38ff 100644 (file)
@@ -45,18 +45,7 @@ my $benchmarks = {
         unless ( $body->state eq 'done' ) {
             die 'baaaaaaaaad';
         }
-    },
-    'HTTP::Body Complete' => sub {
-
-        my $body = HTTP::Body->new( $headers->{'Content-Type'},
-                                    $headers->{'Content-Length'} );
-
-        $body->add($message);
-
-        unless ( $body->state eq 'done' ) {
-            die 'baaaaaaaaad';
-        }
-    },
+    }
 };
 
 if ( eval 'require CGI::Simple' ) {
@@ -73,6 +62,35 @@ if ( eval 'require CGI::Simple' ) {
     };
 }
 
+if ( eval 'require APR::Request' ) {
+
+    require APR;
+    require APR::Pool;
+    require APR::Request;
+    require APR::Request::CGI;
+    require APR::Request::Param;
+
+    $benchmarks->{'APR::Request'} = sub {
+
+        $content->seek( 0, SEEK_SET )
+          or die $!;
+
+        STDIN->fdopen( $content->fileno, 'r' );
+
+        my $pool = APR::Pool->new;
+        my $apr  = APR::Request::CGI->handle($pool);
+
+        if ( my $table = $apr->param ) {
+            $table->do( sub { 1 } );
+        }
+
+        if ( my $body = $apr->body ) {
+            $body->param_class('APR::Request::Param');
+            $body->uploads($pool)->do( sub { 1 } );
+        }
+    };
+}
+
 my @benchmarks =  @ARGV ? @ARGV : qw[ t/data/benchmark/001
                                       t/data/benchmark/002
                                       t/data/benchmark/003 ];
@@ -85,8 +103,6 @@ foreach my $benchmark ( @benchmarks ) {
 
     binmode($content);
 
-    $message = do{ local $/; <$content> };
-
     local %ENV = (
         CONTENT_LENGTH => $headers->{'Content-Length'},
         CONTENT_TYPE   => $headers->{'Content-Type'},