-
-
Save savonarola/490427 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/perl -w | |
use strict; | |
use Benchmark; | |
my $h = { map { $_, $_ } 1..10000 }; | |
timethese( 1000, { | |
each => sub{ my $i = 0; while( my ($k, $v) = each %$h ) { $i++ } }, | |
values => sub{ my $i = 0; foreach my $v (values %$h) { $i++ } }, | |
}); | |
__END__ | |
Benchmark: timing 1000 iterations of each, values... | |
each: 10 wallclock secs ( 9.75 usr + 0.01 sys = 9.76 CPU) @ 102.46/s (n=1000) | |
values: 2 wallclock secs ( 1.98 usr + 0.00 sys = 1.98 CPU) @ 505.05/s (n=1000)+ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment