Except map is painfully slow in void context:
use strict; use warnings; use Benchmark qw( cmpthese ); my @list = map { '' . int(rand(100)) } 1..1000; sub map_test { my %counts = (); map { ++$counts{$_} } @list; 1; } sub foreach_test { my %counts = (); ++$counts{$_} for @list; 1; } cmpthese(-3, { map => \&map_test, foreach => \&foreach_test, });
This is perl, v5.6.1 built for MSWin32-x86-multi-thread Rate map foreach map 953/s -- -25% foreach 1278/s 34% --
This is perl, v5.8.0 built for MSWin32-x86-multi-thread Rate map foreach map 1705/s -- -25% foreach 2288/s 34% --
This is perl, v5.8.0 built for i386-freebsd Rate map foreach map 847/s -- -29% foreach 1190/s 40% --
This may have been fixed since.
In reply to Re^2: Count and List Items in a List
by ikegami
in thread Count and List Items in a List
by Tech77
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |