Skip to content

@rurban /opt_methods_bench.pl
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
benchmark github.com/rurban/perl/commit/7a305aae0b335 opt_methods
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.