File tree Expand file tree Collapse file tree 1 file changed +10
-25
lines changed
pyperformance/data-files/benchmarks/bm_pickle_opt Expand file tree Collapse file tree 1 file changed +10
-25
lines changed Original file line number Diff line number Diff line change 66
77"""
88
9- import tempfile
10- from pathlib import Path
11- import pyperf
129import pickle
1310import pickletools
11+ import pyperf
1412
1513
16- def setup (fname , N ):
17- x = {}
18- for i in range (1 , N ):
19- x [i ] = f"ii{ i :>07} "
20-
21- with open (fname , "wb" ) as fh :
22- pickle .dump (x , fh , protocol = 4 )
23-
24-
25- def run (fname ):
26- with open (fname , "rb" ) as fh :
27- p = fh .read ()
14+ def setup (N : int ) -> bytes :
15+ x = {i : f"ii{ i :>07} " for i in range (N )}
16+ return pickle .dumps (x , protocol = 4 )
2817
29- s = pickletools .optimize (p )
3018
31- with open ( fname . with_suffix ( ".out" ), "wb" ) as fh :
32- fh . write ( s )
19+ def run ( p : bytes ) -> None :
20+ pickletools . optimize ( p )
3321
3422
3523if __name__ == "__main__" :
3624 runner = pyperf .Runner ()
37- N = 1_000_000
38- with tempfile .TemporaryDirectory () as tmp :
39- tmp_path = Path (tmp )
40- fname = tmp_path / "pickle"
41- setup (fname , N )
42- runner .metadata ["description" ] = "Pickletools optimize"
43- runner .bench_func ("pickle_opt" , run , fname )
25+ runner .metadata ["description" ] = "Pickletools optimize"
26+ N = 100_000
27+ payload = setup (N )
28+ runner .bench_func ("pickle_opt" , run , payload )
You can’t perform that action at this time.
0 commit comments