File tree 6 files changed +343084
-0
lines changed
pyperformance/data-files/benchmarks
6 files changed +343084
-0
lines changed Original file line number Diff line number Diff line change @@ -66,6 +66,7 @@ sqlglot <local>
66
66
sqlite_synth <local>
67
67
sympy <local>
68
68
telco <local>
69
+ tomli_loads <local>
69
70
tornado_http <local>
70
71
unpack_sequence <local>
71
72
unpickle <local:pickle>
Load Diff Large diffs are not rendered by default.
Original file line number Diff line number Diff line change
1
+ from urllib .request import urlopen
2
+ import json
3
+ import toml
4
+
5
+ BASE_URL = "https://api.github.com/repos/python/cpython/pulls?per_page=1000&state=all"
6
+
7
+ def main ():
8
+ all_issues = []
9
+ for page in range (1 , 11 ):
10
+ with urlopen (f"{ BASE_URL } &page={ page } " ) as response :
11
+ issues = json .loads (response .read ())
12
+ if not issues :
13
+ break
14
+ all_issues .extend (issues )
15
+ print (f"Page: { page } Total Issues: { len (all_issues )} " )
16
+ with open ("issues.toml" , "w" ) as f :
17
+ f .write (toml .dumps ({"data" : all_issues }))
18
+
19
+ if __name__ == "__main__" :
20
+ main ()
Original file line number Diff line number Diff line change
1
+ [project ]
2
+ name = " pyperformance_bm_tomli_loads"
3
+ requires-python = " >=3.8"
4
+ dependencies = [" pyperf" , " tomli" ]
5
+ urls = {repository = " https://github.com/python/pyperformance" }
6
+ dynamic = [" version" ]
7
+
8
+ [tool .pyperformance ]
9
+ name = " tomli_loads"
10
+ tags = " serialize"
Original file line number Diff line number Diff line change
1
+ tomli == 2.0.1
Original file line number Diff line number Diff line change
1
+ """
2
+ Benchmark ``loads()`` function of the ``tomli`` module
3
+ on a large TOML file of GitHub's real world data generated by
4
+ the ``generate_data.py`` script.
5
+
6
+ It heavily exercises string operations such as concatenation,
7
+ subscripting and iteration.
8
+
9
+ Author: Kumar Aditya
10
+ """
11
+
12
+ from pathlib import Path
13
+
14
+ import pyperf
15
+ import tomli
16
+
17
+ DATA_FILE = Path (__file__ ).parent / "data" / "tomli-bench-data.toml"
18
+
19
+ def bench_tomli_loads (loops : int ) -> float :
20
+ data = DATA_FILE .read_text ('utf-8' )
21
+ range_it = range (loops )
22
+ t0 = pyperf .perf_counter ()
23
+ for _ in range_it :
24
+ tomli .loads (data )
25
+ return pyperf .perf_counter () - t0
26
+
27
+ if __name__ == "__main__" :
28
+ runner = pyperf .Runner ()
29
+ runner .metadata ['description' ] = "Benchmark tomli.loads()"
30
+ runner .bench_time_func ('tomli_loads' , bench_tomli_loads )
You can’t perform that action at this time.
0 commit comments