Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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"
45 changes: 45 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,45 @@
"""The background for this benchmark is that the garbage collection in Python 3.14
Comment thread
pgdr marked this conversation as resolved.
Outdated
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


def setup(fname, N):
import pickle

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):
import pickletools
Comment thread
pgdr marked this conversation as resolved.
Outdated

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
tmp_path = Path(tempfile.mkdtemp())
Comment thread
pgdr marked this conversation as resolved.
Outdated
fname = tmp_path / "pickle"
setup(fname, N)
runner.metadata["description"] = "Pickletools optimize"
runner.bench_func("pickle_opt", run, fname)
Loading