Add proper per-file copyright notices/licenses and top-level license.
[bluesky.git] / microbench / 32kreadbench.py
1 #!/usr/bin/python
2
3 import os, random, sys, time
4
5 def read_files(files, rate=1.0):
6     while True:
7         f = random.sample(files, 1)[0]
8
9         start = time.time()
10         fp = open(f, 'r')
11         blocks = (16 << 20) / 32768
12         offset = random.randrange(blocks) * 32768
13         fp.seek(offset)
14         fp.read(32768)
15         print time.time() - start
16         fp.close()
17
18 if __name__ == '__main__':
19     all_files = []
20     for (path, dirs, files) in iter(os.walk(".")):
21         for f in files:
22             all_files.append(os.path.join(path, f))
23     print len(all_files), "files total"
24     read_files(all_files)