I read the first line of a couple hundred text files with Python.
This runs under a couple seconds on the first time, but it takes only milliseconds to run the second time!!
Why is that ? Is it python ? Is it the operating system (Windows 7 in my case) ?
Here is the script:
import glob
from datetime import datetime
start = datetime.now()
for summary in glob.glob(r"C:\folder\*.txt"):
with open(summary) as f:
line = f.readline()
print line.rstrip().decode('utf-16')
print 'Time: ', datetime.now()-start
That’s the disk cache of the operating system.