Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Re: Why is "for" much slower than "while"?

by Fletch (Chancellor)
on Jan 15, 2010 at 13:13 UTC ( #817634=note: print w/replies, xml ) Need Help??

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

The first version is reading in all of the lines beforehand building up a temporary list (which given a substantially large file may take a good bit of time and/or memory) then iterating over that list; the while reads one line at a time until the end of file is reached so there's nowhere near as much overhead.

The cake is a lie.
The cake is a lie.
The cake is a lie.

  • Comment on Re: Why is "for" much slower than "while"?

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://817634]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (5)
As of 2022-01-24 18:22 GMT
Find Nodes?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:

    Results (64 votes). Check out past polls.