Added APR::Request to benchmark
[catagits/HTTP-Body.git] / scripts / stress.pl
1 #!/usr/bin/perl
2
3 BEGIN {
4     require FindBin;
5 }
6
7 use strict;
8 use warnings;
9 use lib "$FindBin::Bin/../lib";
10
11 use Benchmark   qw[timethese];
12 use HTTP::Body  qw[];
13 use IO::File    qw[O_RDONLY];
14 use YAML        qw[LoadFile Dump];
15
16 my $headers = LoadFile("t/data/multipart/003-headers.yml");
17
18 my $run = sub {
19       my $bsize   = shift;
20       my $content = IO::File->new( "$FindBin::Bin/../t/data/multipart/003-content.dat", O_RDONLY );
21       my $body    = HTTP::Body->new( $headers->{'Content-Type'}, $headers->{'Content-Length'} );
22
23       binmode($content);
24
25       while ( $content->sysread( my $buffer, $bsize ) ) {
26           $body->add($buffer);
27       }
28
29       unless ( $body->state eq 'done' ) {
30           die 'baaaaaaaaad';
31       }
32 };
33
34
35 timethese( 1_000, {
36     'HTTP::Body  256' => sub {  $run->(256) },
37     'HTTP::Body 1024' => sub { $run->(1024) },
38     'HTTP::Body 4096' => sub { $run->(4096) },
39     'HTTP::Body 8192' => sub { $run->(8192) },
40 });