Created
April 8, 2022 18:10
-
-
Save jacoby/bd0e7a4500b251d6d053ef5b9d758747 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
use Benchmark qw(:all); | |
my $count = 1_000_000; | |
timethese( | |
$count, | |
{ | |
'ForLoop' => sub { | |
my @array = 1 .. 1000; | |
for (@array) { | |
shift @array; | |
} | |
}, | |
'WhileLoop' => sub { | |
my @array = 1 .. 1000; | |
for (@array) { | |
shift @array; | |
} | |
}, | |
} | |
); |
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
./forwhile.pl | |
Benchmark: timing 1000000 iterations of ForLoop, WhileLoop... | |
ForLoop: 116 wallclock secs (71.87 usr + 3.64 sys = 75.51 CPU) @ 13243.28/s (n=1000000) | |
WhileLoop: 134 wallclock secs (74.98 usr + 3.76 sys = 78.74 CPU) @ 12700.03/s (n=1000000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment