Skip to content

Instantly share code, notes, and snippets.

@yfuruyama
Created May 5, 2014 02:14
Show Gist options
  • Save yfuruyama/a0be109e8c32747c3560 to your computer and use it in GitHub Desktop.
Save yfuruyama/a0be109e8c32747c3560 to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl
use strict;
use warnings;
use Time::HiRes qw(time);
sub bench(&) {
my $start = time;
shift->();
print time - $start . " sec.\n";
}
bench {
my @a = (1..1_000_000);
my $size = @a;
my $sum;
for (my $i = 0; $i < $size; $i++) {
$sum += $a[$i];
}
};
bench {
my @a = (1..1_000_000);
my $sum;
for my $a (@a) {
$sum += $a;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment