I l@ve RuBoard Previous Section Next Section

14.12 The statcache Module

The statcache module, shown in Example 14-15, contains a function that returns information about files. It's an extension of the os.stat function in that it keeps a cache with recently collected information.

Example 14-15. Using the statcache Module
File: statcache-example-1.py

import statcache
import os, stat, time

now = time.time()
for i in range(1000):
    st = os.stat("samples/sample.txt")
print "os.stat", "=>", time.time() - now

now = time.time()
for i in range(1000):
    st = statcache.stat("samples/sample.txt")
print "statcache.stat", "=>", time.time() - now

print "mode", "=>", oct(stat.S_IMODE(st[stat.ST_MODE]))
print "size", "=>", st[stat.ST_SIZE]
print "last modified", "=>", time.ctime(st[stat.ST_MTIME])

os.stat => 0.371000051498
statcache.stat => 0.0199999809265
mode => 0666
size => 305
last modified => Sun Oct 10 18:39:37 1999
    I l@ve RuBoard Previous Section Next Section