Created
November 24, 2015 20:38
-
-
Save ichesnokov/7feea4c15a868d48e5a0 to your computer and use it in GitHub Desktop.
map-for-foreach speed comparison
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
perl -MBenchmark=cmpthese -E 'cmpthese(10000, { for => sub { my $i = 0; for (1..1000) { $i += $_; } }, map => sub { my $i=0; map { $i += $_; } 1..1000 }, foreach => sub { my $i=0; foreach (1..1000) { $i+=$_; } }, postfix_for => sub { my $i=0; $i+=$_ for 1..1000; }, postfix_foreach => sub { my $i = 0; $i += $_ foreach 1..1000; } });' | |
Rate map postfix_foreach for foreach postfix_for | |
map 12195/s -- -27% -27% -29% -33% | |
postfix_foreach 16667/s 37% -- -0% -3% -8% | |
for 16667/s 37% 0% -- -3% -8% | |
foreach 17241/s 41% 3% 3% -- -5% | |
postfix_for 18182/s 49% 9% 9% 5% -- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment