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


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

In addition to what others have said, some additional (external) factors may also contribute to the results you see, for example:
  1. Disk I/O: different filesystems read in different ways and scheduled I/O can be affected by that as well as block size (see tuning information for "elevator" algorithm on ext3).
  2. CPU allocation: other processes can be competing for the same CPU.
  3. Available RAM: loading an entire file into RAM is much quicker than loading a segment of it into virtual memory or a paging file.