Skip to content

Instantly share code, notes, and snippets.

@cowens
Created July 2, 2009 03:03
Show Gist options
  • Save cowens/139251 to your computer and use it in GitHub Desktop.
Save cowens/139251 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
use strict;
use warnings;
use Benchmark;
sub list {
return scalar @_;
}
sub reference {
return scalar @{$_[0]};
}
my @a = 1 .. 1_000_000;
my %subs = (
list => sub { return list(@a) },
reference => sub { return reference(\@a) }
);
for my $sub (keys %subs) {
print "$sub => ", $subs{$sub}->(), "\n";
}
Benchmark::cmpthese -1, \%subs;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment