Created
June 30, 2014 16:51
-
-
Save ian-kent/6544bc811f416ffb959d to your computer and use it in GitHub Desktop.
Perl subroutine arguments test
This file contains hidden or 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
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
use Time::HiRes qw/ gettimeofday tv_interval /; | |
my $iters = 50000000; | |
package panda { | |
use Mojo::Base -base; | |
my $buf = ""; | |
sub test_ref { | |
my $self = shift; | |
my $args = {@_}; | |
$buf = $args->{foo} . $args->{bar}; | |
$buf = ""; | |
} | |
sub test_opt { | |
my ($self, %args) = @_; | |
$buf = $args{foo} . $args{bar}; | |
$buf = ""; | |
} | |
} | |
my $obj = panda->new; | |
my ($s, $e, $i); | |
{ | |
$s = [gettimeofday]; | |
for (1 .. $iters) { | |
$obj->test_ref(foo => "123", bar => "456"); | |
} | |
$e = [gettimeofday]; | |
$i = tv_interval($s, $e); | |
print "test_ref completed in $i seconds\n"; | |
} | |
{ | |
$s = [gettimeofday]; | |
for (1 .. $iters) { | |
$obj->test_opt(foo => "123", bar => "456"); | |
} | |
$e = [gettimeofday]; | |
$i = tv_interval($s, $e); | |
print "test_opt completed in $i seconds\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment