in reply to Re: Increase speed script
in thread Increase speed script

Ty for you advice. But could you pls tell me why it's better to use the while loop instead of the for loop?

Replies are listed 'Best First'.
Re^3: Increase speed script
by massa (Hermit) on Jul 11, 2008 at 19:48 UTC
    Because the for brings the whole file to the memory before walking thru the lines. This is usually slower than going line-by-line in the file (as the while does) because:
    1. it fills many pages of the memory with the contents of the file, potentially swapping stuff out -- instead of just allocating a couple of pages for a file buffer;
    2. then it walks thru those pages, potentially using cache lines -- instead of pulling the file buffer to the same cache line over and over, freeing cache lines to other stuff;
    3. goes to the disk all at once, blocking until it has read everything -- instead of going to the disk when it had already processed the last chunk of information and then blocking for less time.
    []s, HTH, Massa