public
Created

MooseX::Method::Signatures vs Method::Signatures vs PurePerl

  • Download Gist
gistfile1.pl
Perl
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197
{
package WithMXMS;
 
use Moose;
use MooseX::Method::Signatures;
 
method gndn {}
}
 
 
{
package WithMXMS_immutable;
 
use Moose;
use MooseX::Method::Signatures;
 
method gndn {}
 
__PACKAGE__->meta->make_immutable;
}
 
 
{
package PurePerl;
 
sub new { bless {}, shift };
sub gndn {}
 
# To match what MXMS and MS do
sub gndn_with_shift { my $self = shift; }
}
 
 
# Demonstrating that MS is being affected by a Perl performance issue
# with aliased function calls.
{
package PurePerl_alias;
 
sub new { bless {}, shift };
*gndn = sub {};
 
# To match what MXMS and MS do
*gndn_with_shift = sub { my $self = shift; };
}
 
 
{
package MS_method;
 
use Method::Signatures;
 
sub new { bless {}, shift };
method gndn {}
 
# Disable all argument checks
method gndn_no_check (@_) {}
}
 
 
{
package MS_func;
 
use Method::Signatures;
 
func gndn {}
 
# Disable all argument checks
func gndn_no_check (@_) {}
}
 
 
use v5.14;
use Time::HiRes qw(time);
 
my $Runs = 15_000;
 
say "Running $Runs empty method calls each";
 
{
my $obj = WithMXMS->new;
my $start = time;
$obj->gndn for 1..$Runs;
my $end = time;
say +($end - $start)." seconds for MooseX::Method::Signatures method call";
}
 
 
{
my $obj = WithMXMS_immutable->new;
my $start = time;
$obj->gndn for 1..$Runs;
my $end = time;
say +($end - $start)." seconds for MooseX::Method::Signatures method call (immutable)";
}
 
{
my $obj = PurePerl->new;
my $start = time;
$obj->gndn for 1..$Runs;
my $end = time;
say +($end - $start)." seconds for Pure Perl method call";
}
 
{
my $obj = PurePerl->new;
my $start = time;
$obj->gndn_with_shift for 1..$Runs;
my $end = time;
say +($end - $start)." seconds for Pure Perl method call with 'my \$self = shift'";
}
 
{
my $start = time;
PurePerl::gndn() for 1..$Runs;
my $end = time;
say +($end - $start)." seconds for Pure Perl function call";
}
 
 
{
my $obj = PurePerl_alias->new;
my $start = time;
$obj->gndn for 1..$Runs;
my $end = time;
say +($end - $start)." seconds for Pure Perl aliased method call";
}
 
{
my $obj = PurePerl_alias->new;
my $start = time;
$obj->gndn_with_shift for 1..$Runs;
my $end = time;
say +($end - $start)." seconds for Pure Perl aliased method call with 'my \$self = shift'";
}
 
{
my $start = time;
PurePerl_alias::gndn() for 1..$Runs;
my $end = time;
say +($end - $start)." seconds for Pure Perl aliased function call";
}
 
 
{
my $obj = MS_method->new;
my $start = time;
$obj->gndn for 1..$Runs;
my $end = time;
say +($end - $start)." seconds for Method::Signatures method call";
}
 
 
{
my $obj = MS_method->new;
my $start = time;
$obj->gndn_no_check for 1..$Runs;
my $end = time;
say +($end - $start)." seconds for Method::Signatures method call with no arg checks";
}
 
{
my $start = time;
MS_func::gndn() for 1..$Runs;
my $end = time;
say +($end - $start)." seconds for Method::Signatures func call";
}
 
 
{
my $start = time;
MS_func::gndn_no_check() for 1..$Runs;
my $end = time;
say +($end - $start)." seconds for Method::Signatures func call with no arg checks";
}
 
 
__END__
(Results with Perl 5.14.1 on Macbook i7/2.7Ghz)
(Method::Signatures 20110923.1726)
(MooseX::Method::Signatures 0.37)
 
Running 15000 empty method calls each
1.07040405273438 seconds for MooseX::Method::Signatures method call
1.06590795516968 seconds for MooseX::Method::Signatures method call (immutable)
 
0.00235891342163086 seconds for Pure Perl method call
0.00326395034790039 seconds for Pure Perl method call with 'my $self = shift'
0.00190520286560059 seconds for Pure Perl function call
 
0.00234508514404297 seconds for Pure Perl aliased method call
0.0032198429107666 seconds for Pure Perl aliased method call with 'my $self = shift'
0.00182890892028809 seconds for Pure Perl aliased function call
 
0.00393080711364746 seconds for Method::Signatures method call
0.00322699546813965 seconds for Method::Signatures method call with no arg checks
0.00242090225219727 seconds for Method::Signatures func call
0.00255417823791504 seconds for Method::Signatures func call with no arg checks

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.