Skip to content

Commit c861c2a

Browse files
committed
Improve benchmark usage and output readability.
1 parent 4425247 commit c861c2a

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

lockbench.py

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -101,29 +101,27 @@ def threaded(l, test_func, tcount=10):
101101
repeat_count = 100000
102102
repeat_count_t = 1000
103103

104-
rlock, flock = ('RLock', RLock()), ('FLock', FLock())
104+
rlock, flock = ('threading.RLock', RLock()), ('FastRLock', FLock())
105105
locks = []
106106
args = sys.argv[1:]
107-
if not args:
107+
if 'rlock' in args:
108+
locks.append(rlock)
109+
if 'flock' in args:
110+
locks.append(flock)
111+
if not locks:
108112
locks = [rlock, flock]
109-
else:
110-
if 'rlock' in args:
111-
locks.append(rlock)
112-
if 'flock' in args:
113-
locks.append(flock)
114-
for _ in range(args.count('quick')):
115-
repeat_count = max(10, repeat_count // 100)
116-
repeat_count_t = max(5, repeat_count_t // 10)
117-
assert locks, args
113+
for _ in range(args.count('quick')):
114+
repeat_count = max(10, repeat_count // 100)
115+
repeat_count_t = max(5, repeat_count_t // 10)
118116

119117
for name, lock in locks:
120118
print('Testing %s' % name)
121119
print("sequential (x%d):" % repeat_count)
122120
for function in functions:
123121
timer = Timer(partial(function, lock))
124-
print('%-25s: %.3f sec' % (function.__name__, max(timer.repeat(repeat=4, number=repeat_count))))
122+
print('%-25s: %9.2f msec' % (function.__name__, max(timer.repeat(repeat=4, number=repeat_count)) * 1000.0))
125123

126124
print("threaded 10T (x%d):" % repeat_count_t)
127125
for function in functions:
128126
timer = Timer(partial(threaded, lock, function))
129-
print('%-25s: %.3f sec' % (function.__name__, max(timer.repeat(repeat=4, number=repeat_count_t))))
127+
print('%-25s: %9.2f msec' % (function.__name__, max(timer.repeat(repeat=4, number=repeat_count_t)) * 1000.0))

0 commit comments

Comments
 (0)