public
Created

benchmark github.com/rurban/perl/commit/7a305aae0b335 opt_methods

  • Download Gist
opt_methods_bench.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
use Benchmark;
 
sub Class::method {
my(@args) = @_;
die unless @args == 2
}
 
BEGIN {
@FooClass::ISA = qw(Class);
@MyClass::ISA = qw(FooClass);
}
 
sub method {
my $obj = bless {}, 'Class';
$obj->method($arg);
Class->method('arg');
MyClass->method('arg');
}
 
sub typed_meth {
my Class $obj = bless {}, 'Class';
$obj->method($arg);
Class->method('arg');
MyClass->method('arg');
}
 
sub subroutine {
my $obj = bless {}, 'Class';
Class::method($obj, 'arg');
Class::method('Class', 'arg');
Class::method('MyClass', 'arg');
}
 
sub typed_sub {
my Class $obj = bless {}, 'Class';
Class::method($obj, 'arg');
Class::method('Class', 'arg');
Class::method('MyClass', 'arg');
}
 
subroutine(); method(); #init padlists
typed_sub(); typed_meth();
 
timethese(100_000, { map { $_, \&{$_} }
qw(method typed_meth subroutine typed_sub) });
 
__END__
#new 2011
#patched
$ perl5.15.1d-nt-opt opt_methods_bench.pl
Benchmark: timing 100000 iterations of method, subroutine, typed_meth, typed_sub...
method: 2 wallclock secs ( 1.77 usr + 0.01 sys = 1.78 CPU) @ 56179.78/s (n=100000)
subroutine: 2 wallclock secs ( 1.65 usr + 0.00 sys = 1.65 CPU) @ 60606.06/s (n=100000)
typed_meth: 2 wallclock secs ( 1.76 usr + 0.00 sys = 1.76 CPU) @ 56818.18/s (n=100000)
typed_sub: 2 wallclock secs ( 1.67 usr + 0.00 sys = 1.67 CPU) @ 59880.24/s (n=100000)
 
#unpatched
$ perl5.15.1d-nt opt_methods_bench.pl
Benchmark: timing 100000 iterations of method, subroutine, typed_meth, typed_sub...
method: 2 wallclock secs ( 1.82 usr + 0.00 sys = 1.82 CPU) @ 54945.05/s (n=100000)
subroutine: 1 wallclock secs ( 1.65 usr + 0.00 sys = 1.65 CPU) @ 60606.06/s (n=100000)
typed_meth: 2 wallclock secs ( 1.81 usr + 0.01 sys = 1.82 CPU) @ 54945.05/s (n=100000)
typed_sub: 2 wallclock secs ( 1.64 usr + 0.00 sys = 1.64 CPU) @ 60975.61/s (n=100000)
 
#patched (typed)
Benchmark: timing 100000 iterations of method, subroutine...
method: 2 wallclock secs ( 1.76 usr + 0.01 sys = 1.77 CPU) @ 56497.18/s (n=100000) +3.95%
subroutine: 2 wallclock secs ( 1.66 usr + 0.00 sys = 1.66 CPU) @ 60240.96/s (n=100000) -6.21%
 
#unpatched (typed)
Benchmark: timing 100000 iterations of method, subroutine...
method: 2 wallclock secs ( 1.84 usr + 0.00 sys = 1.84 CPU) @ 54347.83/s (n=100000)
subroutine: 1 wallclock secs ( 1.64 usr + 0.00 sys = 1.64 CPU) @ 60975.61/s (n=100000) -10.87%
 
#old 2002
#patched perl-current (typed)
Benchmark: timing 50000 iterations of method, subroutine...
method: 8 wallclock secs ( 8.67 usr + 0.00 sys = 8.67 CPU) @ 5767.01/s (n=50000)
subroutine: 10 wallclock secs ( 9.30 usr + 0.00 sys = 9.30 CPU) @ 5376.34/s (n=50000)
 
#perl-current (typed)
Benchmark: timing 50000 iterations of method, subroutine...
method: 12 wallclock secs (11.17 usr + 0.00 sys = 11.17 CPU) @ 4476.28/s (n=50000)
subroutine: 9 wallclock secs ( 9.62 usr + 0.00 sys = 9.62 CPU) @ 5197.51/s (n=50000)

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.