-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimer_test.py
More file actions
36 lines (27 loc) · 851 Bytes
/
timer_test.py
File metadata and controls
36 lines (27 loc) · 851 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
import time
code = '''
import random
random.seed(123)
X = [random.randint(0, 100) for n in range(2500)]
done = False
while not done:
done = True
for i, _ in enumerate(X):
if i < len(X) - 1:
a, b = X[i], X[i + 1]
if a > b:
done = False
X[i], X[i + 1] = b, a
'''
def callback(recording):
print('.', end='', flush=True)
start = time.perf_counter()
exec(code, {})
normal_time = time.perf_counter() - start
print('Normal exec: %.5f' % normal_time)
import execorder
start = time.perf_counter()
recording = execorder.exec(code, record_state=False, callback=callback)
recorded_time = time.perf_counter() - start
print('Recorded exec: %.5f (%.2fx slower)' % (recorded_time, recorded_time / normal_time))
print('Recorded', format(recording.steps(), ','), 'execution steps')