[Tutor] File access times

W W srilyk at gmail.com
Wed May 21 18:59:22 CEST 2008


I've just made an interesting observation, and I'm curious if anyone
knows any more about it.

  1 import time
  2
  3 start = time.time()
  4 f = open("test.txt")
  5 f.close()
  6 end = time.time()
  7 print end - start
  8
  9
 10 start = time.time()
 11 f = open("/home/wayne/python_files/test/test.txt")
 12 f.close()
 13 end = time.time()
 14 print end - start

As you can see, the open/timing dialogs are precisely the same, yet as
I've run it, I get these results:

------------
2.59876251221e-05
1.8835067749e-05
------------
3.38554382324e-05
1.90734863281e-05
------------
2.8133392334e-05
1.90734863281e-05
------------

However, when I switch the order, so the full path is first, I get
similar results.

Granted, .000028 vs .000019 (seconds?) isn't terribly long, but it
*is* a discrepancy, and I find it even more puzzling that the second
access is faster, regardless of how detailed the path is. Could it be
that the file is stored in RAM and "remembered" even though it's been
closed?

Just curious,
Wayne


-- 
To be considered stupid and to be told so is more painful than being
called gluttonous, mendacious, violent, lascivious, lazy, cowardly:
every weakness, every vice, has found its defenders, its rhetoric, its
ennoblement and exaltation, but stupidity hasn't. - Primo Levi


More information about the Tutor mailing list