File tree Expand file tree Collapse file tree 2 files changed +54
-0
lines changed
pyperformance/data-files/benchmarks/bm_pickle_opt Expand file tree Collapse file tree 2 files changed +54
-0
lines changed Original file line number Diff line number Diff line change 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"
Original file line number Diff line number Diff line change 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 )
You can’t perform that action at this time.
0 commit comments