@@ -17,16 +17,18 @@ def speed_comparison(source: str, test_name: str):
17
17
print ()
18
18
print (f"Starting speed test: { test_name } " )
19
19
20
- def helper (data , label , lazy ):
21
- timings = {}
22
- t0 = time .perf_counter ()
20
+ def load_helper (data , label , timings , lazy ):
23
21
codes = []
22
+ t0 = time .perf_counter ()
24
23
for _ in range (1000 ):
25
24
code = marshal .loads (data , lazy = lazy )
26
25
codes .append (code )
27
26
t1 = time .perf_counter ()
28
27
print (f"{ label } load: { t1 - t0 :.3f} " )
29
28
timings ["load" ] = t1 - t0
29
+ return codes
30
+
31
+ def exec_helper (codes , label , timings ):
30
32
timings ["execs" ] = []
31
33
for i in range (4 ):
32
34
t3 = time .perf_counter ()
@@ -35,14 +37,27 @@ def helper(data, label, lazy):
35
37
t4 = time .perf_counter ()
36
38
print (f"{ label } exec #{ i + 1 } : { t4 - t3 :.3f} " )
37
39
timings ["execs" ].append (t4 - t3 )
40
+
41
+ def helper (data , label , timings , lazy ):
42
+ t0 = time .perf_counter ()
43
+ codes = load_helper (data , label , timings , lazy )
44
+ exec_helper (codes , label , timings )
45
+ t4 = time .perf_counter ()
38
46
print (f" { label } total: { t4 - t0 :.3f} " )
39
47
return timings
40
48
41
49
code = compile (source , "<old>" , "exec" )
42
50
data = marshal .dumps (code )
43
- classic_timings = helper (data , "Classic" , lazy = False )
44
51
45
- new_timings = helper (data , "Lazy" , lazy = True )
52
+ # new_timings = helper(data, "Lazy", new_timings, lazy=True)
53
+ # classic_timings = helper(data, "Classic", classic_timings, lazy=False)
54
+
55
+ new_timings = {}
56
+ classic_timings = {}
57
+ classic_codes = load_helper (data , "Classic" , classic_timings , lazy = False )
58
+ lazy_codes = load_helper (data , "Lazy" , new_timings , lazy = True )
59
+ exec_helper (classic_codes , "Classic" , classic_timings )
60
+ exec_helper (lazy_codes , "Lazy" , new_timings )
46
61
47
62
if classic_timings and new_timings :
48
63
0 commit comments