-
-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4a69828
commit 9c58774
Showing
6 changed files
with
343,084 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
343,022 changes: 343,022 additions & 0 deletions
343,022
pyperformance/data-files/benchmarks/bm_tomli_loads/data/tomli-bench-data.toml
Large diffs are not rendered by default.
Oops, something went wrong.
20 changes: 20 additions & 0 deletions
20
pyperformance/data-files/benchmarks/bm_tomli_loads/generate_data.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from urllib.request import urlopen | ||
import json | ||
import toml | ||
|
||
BASE_URL = "https://api.github.com/repos/python/cpython/pulls?per_page=1000&state=all" | ||
|
||
def main(): | ||
all_issues = [] | ||
for page in range(1, 11): | ||
with urlopen(f"{BASE_URL}&page={page}") as response: | ||
issues = json.loads(response.read()) | ||
if not issues: | ||
break | ||
all_issues.extend(issues) | ||
print(f"Page: {page} Total Issues: {len(all_issues)}") | ||
with open("issues.toml", "w") as f: | ||
f.write(toml.dumps({"data": all_issues})) | ||
|
||
if __name__ == "__main__": | ||
main() |
10 changes: 10 additions & 0 deletions
10
pyperformance/data-files/benchmarks/bm_tomli_loads/pyproject.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
[project] | ||
name = "pyperformance_bm_tomli_loads" | ||
requires-python = ">=3.8" | ||
dependencies = ["pyperf", "tomli"] | ||
urls = {repository = "https://github.com/python/pyperformance"} | ||
dynamic = ["version"] | ||
|
||
[tool.pyperformance] | ||
name = "tomli_loads" | ||
tags = "serialize" |
1 change: 1 addition & 0 deletions
1
pyperformance/data-files/benchmarks/bm_tomli_loads/requirements.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
tomli==2.0.1 |
30 changes: 30 additions & 0 deletions
30
pyperformance/data-files/benchmarks/bm_tomli_loads/run_benchmark.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
""" | ||
Benchmark ``loads()`` function of the ``tomli`` module | ||
on a large TOML file of GitHub's real world data generated by | ||
the ``generate_data.py`` script. | ||
It heavily exercises string operations such as concatenation, | ||
subscripting and iteration. | ||
Author: Kumar Aditya | ||
""" | ||
|
||
from pathlib import Path | ||
|
||
import pyperf | ||
import tomli | ||
|
||
DATA_FILE = Path(__file__).parent / "data" / "tomli-bench-data.toml" | ||
|
||
def bench_tomli_loads(loops: int) -> float: | ||
data = DATA_FILE.read_text('utf-8') | ||
range_it = range(loops) | ||
t0 = pyperf.perf_counter() | ||
for _ in range_it: | ||
tomli.loads(data) | ||
return pyperf.perf_counter() - t0 | ||
|
||
if __name__ == "__main__": | ||
runner = pyperf.Runner() | ||
runner.metadata['description'] = "Benchmark tomli.loads()" | ||
runner.bench_time_func('tomli_loads', bench_tomli_loads) |