sorry konobi, not enough of a perf win, so lets wait till we get something more befor...
[gitmo/Moose.git] / benchmarks / method_modifiers.pl
CommitLineData
f50f7707 1#!perl
2
3### MODULES
4
5{
6 package PlainParent;
7 sub new { bless {} => shift }
8 sub method { "P" }
9}
10{
11 package MooseParent;
12 use Moose;
13 sub method { "P" }
14}
15
16{
17 package CMMChild::Before;
18 use Class::Method::Modifiers;
19 use base 'PlainParent';
20
21 before method => sub { "B" };
22}
23{
24 package MooseBefore;
25 use Moose;
2727db28 26 extends 'MooseParent';
f50f7707 27
28 before method => sub { "B" };
29}
30
31{
32 package CMMChild::Around;
33 use Class::Method::Modifiers;
34 use base 'PlainParent';
35
36 around method => sub { shift->() . "A" };
37}
38{
39 package MooseAround;
40 use Moose;
2727db28 41 extends 'MooseParent';
f50f7707 42
43 around method => sub { shift->() . "A" };
44}
45
46{
47 package CMMChild::AllThree;
48 use Class::Method::Modifiers;
49 use base 'PlainParent';
50
51 before method => sub { "B" };
52 around method => sub { shift->() . "A" };
53 after method => sub { "Z" };
54}
55{
56 package MooseAllThree;
57 use Moose;
2727db28 58 extends 'MooseParent';
f50f7707 59
60 before method => sub { "B" };
61 around method => sub { shift->() . "A" };
62 after method => sub { "Z" };
63}
64
65use Benchmark qw(cmpthese);
66use Benchmark ':hireswallclock';
67
68my $rounds = -5;
69
70my $cmm_before = CMMChild::Before->new();
71my $cmm_around = CMMChild::Around->new();
72my $cmm_allthree = CMMChild::AllThree->new();
73
74my $moose_before = MooseBefore->new();
75my $moose_around = MooseAround->new();
76my $moose_allthree = MooseAllThree->new();
77
78print "\nBEFORE\n";
79cmpthese($rounds, {
80 Moose => sub { $moose_before->method() },
81 ClassMethodModifiers => sub { $cmm_before->method() },
82}, 'noc');
83
84print "\nAROUND\n";
85cmpthese($rounds, {
86 Moose => sub { $moose_around->method() },
87 ClassMethodModifiers => sub { $cmm_around->method() },
88}, 'noc');
89
90print "\nALL THREE\n";
91cmpthese($rounds, {
92 Moose => sub { $moose_allthree->method() },
93 ClassMethodModifiers => sub { $cmm_allthree->method() },
94}, 'noc');
95