Skip to content

Instantly share code, notes, and snippets.

@ian-kent
Created June 30, 2014 16:51
Show Gist options
  • Save ian-kent/6544bc811f416ffb959d to your computer and use it in GitHub Desktop.
Save ian-kent/6544bc811f416ffb959d to your computer and use it in GitHub Desktop.
Perl subroutine arguments test
#!/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