Note that there are some explanatory texts on larger screens.

plurals
  1. POIs python automagically parallelizing IO- and CPU- or memory-bound sections?
    primarykey
    data
    text
    <p>This is a follow-up questions on a <a href="https://stackoverflow.com/questions/849058/is-it-possible-to-speed-up-python-io">previous one</a>.</p> <p>Consider this code, which is less toyish than the one in the <a href="https://stackoverflow.com/questions/849058/is-it-possible-to-speed-up-python-io">previous question</a> (but still much simpler than my real one)</p> <pre><code>import sys data=[] for line in open(sys.argv[1]): data.append(line[-1]) print data[-1] </code></pre> <p>Now, I was expecting a longer run time (my benchmark file is 65150224 lines long), possibly much longer. This was not the case, it runs in ~ 2 minutes on the same hw as before!</p> <p>Is it data.append() very lightweight? I don't believe so, thus I wrote this fake code to test it:</p> <pre><code>data=[] counter=0 string="a\n" for counter in xrange(65150224): data.append(string[-1]) print data[-1] </code></pre> <p>This runs in 1.5 to 3 minutes (there is strong variability among runs)</p> <p>Why don't I get 3.5 to 5 minutes in the former program? Obviously data.append() is happening in parallel with the IO. </p> <p>This is good news! </p> <p>But how does it work? Is it a documented feature? Is there any requirement on my code that I should follow to make it works as much as possible (besides load-balancing IO and memory/CPU activities)? Or is it just plain buffering/caching in action?</p> <p>Again, I tagged "linux" this question, because I'm interested only in linux-specific answers. Feel free to give OS-agnostic, or even other-OS answers, if you think it's worth doing.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload