Update benchmarks
[gitmo/Mouse.git] / author / pp-vs-xs-with-forking.pl
CommitLineData
24490789 1#!perl -w
2
3use strict;
4use Config; printf "Perl/%vd (%s)\n", $^V, $Config{archname};
5
6use Benchmark qw(:hireswallclock);
7use Benchmark::Forking qw(cmpthese);
8
9use Encode (); # pre-load for Interface::Test
10use HTTP::Request ();
11
12sub new_he{
7deba168 13 my($use_pp, $any_moose) = @_;
24490789 14 $ENV{MOUSE_PUREPERL} = $use_pp;
7deba168 15 $ENV{ANY_MOOSE} = $any_moose if defined $any_moose;
24490789 16
17 require HTTP::Engine;
18
19 return HTTP::Engine->new(
20 interface => {
21 module => 'Test',
22 request_handler => sub {
23 my($request) = @_;
24
25 return HTTP::Engine::Response->new(body => "Hello, world!\n");
26 },
27 },
28 );
29}
30
31my $req = HTTP::Request->new(GET => 'http://localhost/');
32
33print "load HTTP::Engine, new(), and run()\n";
7deba168 34cmpthese -2 => {
24490789 35 'XS' => sub {
36 my $he = new_he(0);
37 $he->run($req, env => \%ENV);
38 },
39 'PP' => sub {
40 my $he = new_he(1);
41 $he->run($req, env => \%ENV);
42 },
7deba168 43 'Moose' => sub {
44 my $he = new_he(0, 'Moose');
45 $he->run($req, env => \%ENV);
46 },
24490789 47};
48
49print "load HTTP::Engine, new(), and run() * 100\n";
7deba168 50cmpthese -2 => {
24490789 51 'XS' => sub {
52 my $he = new_he(0);
53 $he->run($req, env => \%ENV) for 1 .. 100;
54 },
55 'PP' => sub {
56 my $he = new_he(1);
57 $he->run($req, env => \%ENV) for 1 .. 100;
58 },
7deba168 59 'Moose' => sub {
60 my $he = new_he(0, 'Moose');
61 $he->run($req, env => \%ENV) for 1 .. 100;
62 },
24490789 63};
64