python - Why file read is faster on reading again? -


size = 1<<16 def justread(file):     open(file, 'rb') f:         while f.read(size):             pass 

the first time run function on 700mb file took 19 secs. when repeated
reading same file again time took dropped 0.5secs.
repeated many files , results similar.
going on here?

the operating system caches file in memory upon first read, , second time read memory instead of hard disk. of course memory faster.


Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -