Created
May 5, 2014 02:14
-
-
Save yfuruyama/a0be109e8c32747c3560 to your computer and use it in GitHub Desktop.
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(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