-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmeasure.py
More file actions
34 lines (24 loc) · 878 Bytes
/
Copy pathmeasure.py
File metadata and controls
34 lines (24 loc) · 878 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
"""Look for reference-count growth across repeated dtype lifetimes."""
import gc
import sys
if not hasattr(sys, "gettotalrefcount"):
raise SystemExit("Use the debug Python from the shared setup in ../SETUP.md.")
from numpy.dtypes import StringDType
def exercise(count):
for _ in range(count):
dtype = StringDType()
del dtype
def measure(count):
gc.collect()
before = sys.gettotalrefcount()
exercise(count)
gc.collect()
return sys.gettotalrefcount() - before
if __name__ == "__main__":
# Warm caches and interpreter specialization before collecting samples.
for _ in range(5):
measure(1000)
# Compare sizes to distinguish per-construction growth from fixed overhead.
for count in (0, 100, 1000):
deltas = [measure(count) for _ in range(5)]
print(f"{count:4d} constructions: {deltas}")