Skip to content

Commit 0147c02

Browse files
committed
Add additional gc benchmark with pickletools (#437)
1 parent cdbf33b commit 0147c02

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[project]
2+
name = "pyperformance_bm_pickle_opt"
3+
requires-python = ">=3.8"
4+
dependencies = ["pyperf"]
5+
urls = {repository = "https://github.com/python/pyperformance"}
6+
dynamic = ["version"]
7+
8+
[tool.pyperformance]
9+
name = "pickle_opt"
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
"""The background for this benchmark is that the garbage collection in Python 3.14
2+
had a performance regression, see
3+
4+
* https://github.com/python/cpython/issues/140175
5+
* https://github.com/python/cpython/issues/139951
6+
7+
"""
8+
9+
import tempfile
10+
from pathlib import Path
11+
12+
import pyperf
13+
14+
15+
def setup(fname, N):
16+
import pickle
17+
18+
x = {}
19+
for i in range(1, N):
20+
x[i] = f"ii{i:>07}"
21+
22+
with open(fname, "wb") as fh:
23+
pickle.dump(x, fh, protocol=4)
24+
25+
26+
def run(fname):
27+
import pickletools
28+
29+
with open(fname, "rb") as fh:
30+
p = fh.read()
31+
32+
s = pickletools.optimize(p)
33+
34+
with open(fname.with_suffix(".out"), "wb") as fh:
35+
fh.write(s)
36+
37+
38+
if __name__ == "__main__":
39+
runner = pyperf.Runner()
40+
N = 1_000_000
41+
tmp_path = Path(tempfile.mkdtemp())
42+
fname = tmp_path / "pickle"
43+
setup(fname, N)
44+
runner.metadata["description"] = "Pickletools optimize"
45+
runner.bench_func("pickle_opt", run, fname)

0 commit comments

Comments
 (0)