Last active
August 29, 2015 14:15
-
-
Save schwern/b4cc353399abae1c7f5a to your computer and use it in GitHub Desktop.
Overhead of a wrapper function in Perl
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
use strict; | |
use warnings; | |
use Benchmark qw(cmpthese); | |
sub match { $_[0] =~ $_[1] } | |
sub wrapper { match(@_) } | |
sub wrapper_alias_args { &match } | |
my @args = ("foo", qr/bar/); | |
cmpthese -3, { | |
match => sub { match(@args) }, | |
wrapper => sub { wrapper(@args) }, | |
wrapper_alias_args => sub { wrapper_alias_args(@args) }, | |
}; | |
__END__ | |
Rate wrapper wrapper_alias_args match | |
wrapper 1124156/s -- -6% -18% | |
wrapper_alias_args 1199177/s 7% -- -12% | |
match 1363269/s 21% 14% -- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Wow, changing
$args[1]
from a string to a regex chops performance in half. Weird. I guess it's more expensive to copy?