Skip to content

Commit b1b8a37

Browse files
committed
Benchmark importing all standard library modules
Note this will change if we add or remove modules from the standard library. We could alternatively hardcode a list of standard library modules.
1 parent 5c46c3a commit b1b8a37

File tree

4 files changed

+40
-0
lines changed

4 files changed

+40
-0
lines changed

pyperformance/data-files/benchmarks/MANIFEST

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ sqlglot_parse <local:sqlglot>
8181
sqlglot_transpile <local:sqlglot>
8282
sqlglot_optimize <local:sqlglot>
8383
sqlite_synth <local>
84+
stdlib_startup <local>
8485
sympy <local>
8586
telco <local>
8687
tomli_loads <local>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[project]
2+
name = "pyperformance_stdlib_startup"
3+
requires-python = ">=3.8"
4+
dependencies = []
5+
urls = {repository = "https://github.com/python/pyperformance"}
6+
dynamic = ["version"]
7+
8+
[tool.pyperformance]
9+
name = "stdlib_startup"
10+
tags = "startup"

pyperformance/data-files/benchmarks/bm_stdlib_startup/requirements.txt

Whitespace-only changes.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import os
2+
import sys
3+
import subprocess
4+
import tempfile
5+
6+
import pyperf
7+
8+
if __name__ == "__main__":
9+
runner = pyperf.Runner(values=10)
10+
11+
runner.metadata['description'] = "Performance of importing standard library modules"
12+
args = runner.parse_args()
13+
14+
with tempfile.TemporaryDirectory() as tmp:
15+
main = os.path.join(tmp, "main.py")
16+
with open(main, "w") as f:
17+
f.write("""
18+
import importlib
19+
import sys
20+
for m in sys.stdlib_module_names:
21+
if m in {"antigravity", "this"}:
22+
continue
23+
try:
24+
importlib.import_module(m)
25+
except ImportError:
26+
pass
27+
""")
28+
command = [sys.executable, main]
29+
runner.bench_command('stdlib_startup', command)

0 commit comments

Comments
 (0)