Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[project]
name = "pyperformance_bm_pickle_opt"
requires-python = ">=3.8"
dependencies = ["pyperf"]
urls = {repository = "https://github.com/python/pyperformance"}
dynamic = ["version"]

[tool.pyperformance]
name = "pickle_opt"
43 changes: 43 additions & 0 deletions pyperformance/data-files/benchmarks/bm_pickle_opt/run_benchmark.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
"""The background for this benchmark is that the garbage collection in
Python 3.14.0 had a performance regression, see

* https://github.com/python/cpython/issues/140175
* https://github.com/python/cpython/issues/139951

"""

import tempfile
from pathlib import Path
import pyperf
import pickle
import pickletools


def setup(fname, N):
x = {}
for i in range(1, N):
x[i] = f"ii{i:>07}"

with open(fname, "wb") as fh:
pickle.dump(x, fh, protocol=4)


def run(fname):
with open(fname, "rb") as fh:
p = fh.read()

s = pickletools.optimize(p)

with open(fname.with_suffix(".out"), "wb") as fh:
fh.write(s)


if __name__ == "__main__":
runner = pyperf.Runner()
N = 1_000_000
with tempfile.TemporaryDirectory() as tmp:
tmp_path = Path(tmp)
fname = tmp_path / "pickle"
setup(fname, N)
runner.metadata["description"] = "Pickletools optimize"
runner.bench_func("pickle_opt", run, fname)
Loading