Last active
August 29, 2015 14:26
-
-
Save ab5tract/1c394b6ef32bbf27374c to your computer and use it in GitHub Desktop.
for-vs-while-int-vs-Int
This file contains 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
my $begin = DateTime.now; | |
say "Beginning at $begin"; | |
my int @range = 0..^400; | |
my $count = 0; | |
for @range -> int $i { | |
for @range -> int $j { | |
for @range -> int $k { | |
$count = $count + 1; | |
} | |
} | |
} | |
say "done $count in {now - $begin.Instant} seconds"; |
This file contains 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
# doing time inside the script, so that we don't measure startup time | |
my $begin = now; | |
say "Starting at $begin"; | |
my int $count = 0; | |
my int $i = 0; | |
while $i < 400 { | |
my int $j = 0; | |
while $j < 400 { | |
my int $k = 0; | |
while $k < 400 { | |
$k = $k + 1; | |
$count = $count + 1; | |
} | |
$j = $j + 1; | |
} | |
$i = $i + 1; | |
} | |
my $interval = now - $begin; | |
print "done $count in $interval seconds\n"; |
This file contains 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
done 64000000 in 4.035 seconds |
This file contains 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
perl benchmark.pl | |
done 64000000 | |
10.51user 0.00system 0:10.51elapsed 100%CPU (0avgtext+0avgdata 7536maxresident)k | |
0inputs+0outputs (0major+527minor)pagefaults 0swaps |
This file contains 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
my $count; | |
my $i = 0; | |
while ( $i < 400 ) { | |
my $j = 0; | |
while ( $j < 400 ) { | |
my $k = 0; | |
while ( $k < 400 ) { | |
$k = $k + 1; | |
$count = $count + 1; | |
} | |
$j = $j + 1; | |
} | |
$i = $i + 1; | |
} | |
print "done $count\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment