I don't know how to check for memory usage (rather than the blunt method of watching the task manager) but here are some speed tests. It appears from this test that they are very simlar in speed for this summing operation. For is the winner but i'm not sure its a noticable portion until you climb into the severl hundered thousand range.
use strict;
use warnings;
use Benchmark qw(:all) ;
my $to = 10_000;
cmpthese(-5,
{
'Map100k' => sub { my $sum = 0;
map { $sum += $_ }
1 .. 100_000;
},
'For100k' => sub { my $sum = 0;
$sum += $_ for 1 .. 100_000;
},
'Map10k' => sub { my $sum = 0;
map { $sum += $_ }
1 .. 10_000;
},
'For10k' => sub { my $sum = 0;
$sum += $_ for 1 .. 10_000;
},
'Map1k' => sub { my $sum = 0;
map { $sum += $_ }
1 .. 1_000;
},
'For1k' => sub { my $sum = 0;
$sum += $_ for 1 .. 1_000;
},
});
__END__
Rate Map100k For100k Map10k For10k Map1k For1k
Map100k 18.6/s -- -19% -90% -92% -99% -99%
For100k 23.1/s 24% -- -88% -90% -99% -99%
Map10k 187/s 905% 709% -- -22% -91% -92%
For10k 239/s 1182% 933% 28% -- -89% -90%
Map1k 2077/s 11052% 8880% 1009% 770% -- -13%
For1k 2387/s 12715% 10219% 1175% 899% 15% --