Skip to content
Open
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
Prev Previous commit
Get rid of files
  • Loading branch information
pgdr committed Nov 12, 2025
commit 6e8f8f8de4fe679596670c73eb98d7227f29b927
35 changes: 10 additions & 25 deletions pyperformance/data-files/benchmarks/bm_pickle_opt/run_benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,38 +6,23 @@

"""

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


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()
def setup(N: int) -> bytes:
x = {i: f"ii{i:>07}" for i in range(N)}
return pickle.dumps(x, protocol=4)

s = pickletools.optimize(p)

with open(fname.with_suffix(".out"), "wb") as fh:
fh.write(s)
def run(p: bytes) -> None:
pickletools.optimize(p)


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)
runner.metadata["description"] = "Pickletools optimize"
N = 100_000
payload = setup(N)
runner.bench_func("pickle_opt", run, payload)
Loading