forked from grantjenks/python-diskcache
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbenchmark_glob.py
More file actions
40 lines (29 loc) · 937 Bytes
/
benchmark_glob.py
File metadata and controls
40 lines (29 loc) · 937 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
"Benchmark glob.glob1 as used by django.core.cache.backends.filebased."
import os
import os.path as op
import shutil
import timeit
from utils import secs
shutil.rmtree('tmp', ignore_errors=True)
os.mkdir('tmp')
size = 12
cols = ('Count', 'Time')
template = ' '.join(['%' + str(size) + 's'] * len(cols))
print()
print(' '.join(['=' * size] * len(cols)))
print('Timings for glob.glob1')
print('-'.join(['-' * size] * len(cols)))
print(template % ('Count', 'Time'))
print(' '.join(['=' * size] * len(cols)))
for count in [10 ** exp for exp in range(6)]:
for value in range(count):
with open(op.join('tmp', '%s.tmp' % value), 'wb') as writer:
pass
delta = timeit.timeit(
stmt="glob.glob1('tmp', '*.tmp')",
setup='import glob',
number=100
)
print(template % (count, secs(delta)))
print(' '.join(['=' * size] * len(cols)))
shutil.rmtree('tmp', ignore_errors=True)