Added APR::Request to benchmark
[catagits/HTTP-Body.git] / scripts / stress.pl
CommitLineData
d10b9732 1#!/usr/bin/perl
2
3BEGIN {
4 require FindBin;
5}
6
7use strict;
8use warnings;
9use lib "$FindBin::Bin/../lib";
10
11use Benchmark qw[timethese];
12use HTTP::Body qw[];
13use IO::File qw[O_RDONLY];
14use YAML qw[LoadFile Dump];
15
16my $headers = LoadFile("t/data/multipart/003-headers.yml");
17
18my $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
35timethese( 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});