Skip to content

Commit 9ee145b

Browse files
committed
Add timing using array.array as well
1 parent da62e36 commit 9ee145b

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

scripts/time_unmarshal.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Time the cost of unmarshalling many objects vs. the bytecode interpreter."""
22

3+
import array
34
import marshal
45
import time
56

@@ -31,5 +32,15 @@ def main():
3132
dt = t1 - t0
3233
print(f"Code: total {dt:.3f} sec; {1e9*dt/n/k:.3f} nsec per value")
3334

35+
# And do it with arrays
36+
a = array.array("L", t)
37+
assert tuple(a) == t
38+
t0 = time.time()
39+
for i in range(k):
40+
marshal.loads(s)
41+
t1 = time.time()
42+
dt = t1 - t0
43+
print(f"Array: total {dt:.3f} sec; {1e9*dt/n/k:.3f} nsec per value")
44+
3445

3546
main()

0 commit comments

Comments
 (0)