Help for this page
use strict; use Benchmark qw(:all); ... "Foreach" => sub{ my %hash = map{$_=>1} (1..10000);}, "Map" => sub{ my %hash; $hash{$_} = 1 foreach (1..10000);} })
Benchmark: timing 1000 iterations of Foreach, Map... Foreach: 54 wallclock secs (49.54 usr + 0.12 sys = 49.66CPU) @ 20. +14/s (n=1000) Map: 31 wallclock secs (28.80 usr + 0.06 sys = 28.86CPU) @ 34. +65/s (n=1000)