No need for the intermediate copy.
[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";
712c90b5 10use lib "$FindBin::Bin/../t/lib";
d10b9732 11
12use Benchmark qw[timethese];
13use HTTP::Body qw[];
14use IO::File qw[O_RDONLY];
712c90b5 15use PAML qw[LoadFile];
d10b9732 16
712c90b5 17my $headers = LoadFile("t/data/multipart/003-headers.pml");
d10b9732 18
19my $run = sub {
20 my $bsize = shift;
21 my $content = IO::File->new( "$FindBin::Bin/../t/data/multipart/003-content.dat", O_RDONLY );
22 my $body = HTTP::Body->new( $headers->{'Content-Type'}, $headers->{'Content-Length'} );
23
24 binmode($content);
25
26 while ( $content->sysread( my $buffer, $bsize ) ) {
27 $body->add($buffer);
28 }
29
30 unless ( $body->state eq 'done' ) {
31 die 'baaaaaaaaad';
32 }
33};
34
35
36timethese( 1_000, {
37 'HTTP::Body 256' => sub { $run->(256) },
38 'HTTP::Body 1024' => sub { $run->(1024) },
39 'HTTP::Body 4096' => sub { $run->(4096) },
40 'HTTP::Body 8192' => sub { $run->(8192) },
41});