Skip to content

Instantly share code, notes, and snippets.

@ian-kent
Created July 1, 2014 09:14
Show Gist options
  • Save ian-kent/50aa872d2091271d2bf3 to your computer and use it in GitHub Desktop.
Save ian-kent/50aa872d2091271d2bf3 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_shift {
my $self = shift;
my %args = @_;
$buf = $args{foo} . $args{bar};
$buf = "";
}
sub test_slurp {
my ($self, %args) = @_;
$buf = $args{foo} . $args{bar};
$buf = "";
}
}
my $obj = panda->new;
my ($s, $e, $i);
{
$s = [gettimeofday];
for (1 .. $iters) {
$obj->test_shift(foo => "123", bar => "456");
}
$e = [gettimeofday];
$i = tv_interval($s, $e);
print "test_shift completed in $i seconds\n";
}
{
$s = [gettimeofday];
for (1 .. $iters) {
$obj->test_slurp(foo => "123", bar => "456");
}
$e = [gettimeofday];
$i = tv_interval($s, $e);
print "test_slurp completed in $i seconds\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment