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

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -