http://www.perlmonks.org?node_id=819261


in reply to Re: Why is "for" much slower than "while"?
in thread Why is "for" much slower than "while"?

My results from gam3's script, second version:

/dev/null
                Rate        for     whyfor      while while_list   for_list
for         280029/s         --       -16%       -17%       -73%       -74%
whyfor      333697/s        19%         --        -1%       -68%       -69%
while       338448/s        21%         1%         --       -68%       -69%
while_list 1050567/s       275%       215%       210%         --        -3%
for_list   1079903/s       286%       224%       219%         3%         --
/usr/share/dict/words
             Rate        for     whyfor while_list      while   for_list
for        3.67/s         --       -39%       -41%       -42%       -51%
whyfor     5.99/s        63%         --        -4%        -5%       -21%
while_list 6.26/s        71%         5%         --        -0%       -17%
while      6.27/s        71%         5%         0%         --       -17%
for_list   7.56/s       106%        26%        21%        21%         --
/etc/passwd
              Rate     whyfor        for while_list      while   for_list
whyfor     13584/s         --       -13%       -17%       -30%       -56%
for        15664/s        15%         --        -5%       -19%       -49%
while_list 16411/s        21%         5%         --       -15%       -47%
while      19273/s        42%        23%        17%         --       -38%
for_list   30882/s       127%        97%        88%        60%         --
  • Comment on Re^2: Why is "for" much slower than "while"?