Created
February 26, 2019 21:56
-
-
Save petdance/8858405f4456837d20e143306dc3425b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ cat prototypes-timings.pl | |
#!/var/perl/bin/perl | |
use warnings; | |
use strict; | |
use 5.020; | |
no warnings 'experimental::signatures'; | |
use feature 'signatures'; | |
use Benchmark qw( :all ); | |
timethese( 10_000_000, { | |
shifted => sub { funcshifted( 1, 2 ) }, | |
shiftedp => sub { funcshiftedp( 1, 2 ) }, | |
assigned => sub { funcassigned( 1, 2 ) }, | |
assignedp => sub { funcassignedp( 1, 2 ) }, | |
signature => sub { funcsignature( 1, 2 ) }, | |
signaturep => sub { funcsignaturep( 1, 2 ) }, | |
} ); | |
exit 0; | |
sub funcshifted { | |
my $x = shift; | |
my $y = shift; | |
} | |
sub funcshiftedp :prototype($$) { | |
my $x = shift; | |
my $y = shift; | |
} | |
sub funcassigned { | |
my ($x,$y) = @_; | |
} | |
sub funcassignedp :prototype($$) { | |
my ($x,$y) = @_; | |
} | |
sub funcsignature ($x,$y) { | |
} | |
sub funcsignaturep :prototype($$) ($x,$y) { | |
} | |
$ perl prototypes-timings.pl | |
Benchmark: timing 10000000 iterations of assigned, assignedp, shifted, shiftedp, signature, signaturep... | |
assigned: 1 wallclock secs ( 1.85 usr + 0.00 sys = 1.85 CPU) @ 5405405.41/s (n=10000000) | |
assignedp: 2 wallclock secs ( 1.84 usr + 0.00 sys = 1.84 CPU) @ 5434782.61/s (n=10000000) | |
shifted: 2 wallclock secs ( 2.09 usr + 0.00 sys = 2.09 CPU) @ 4784689.00/s (n=10000000) | |
shiftedp: 1 wallclock secs ( 2.12 usr + 0.00 sys = 2.12 CPU) @ 4716981.13/s (n=10000000) | |
signature: 4 wallclock secs ( 3.28 usr + 0.00 sys = 3.28 CPU) @ 3048780.49/s (n=10000000) | |
signaturep: 3 wallclock secs ( 3.30 usr + 0.00 sys = 3.30 CPU) @ 3030303.03/s (n=10000000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment