Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Benchmark importing all standard library modules #338

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pyperformance/data-files/benchmarks/MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ sqlglot_parse <local:sqlglot>
sqlglot_transpile <local:sqlglot>
sqlglot_optimize <local:sqlglot>
sqlite_synth <local>
stdlib_startup <local>
sympy <local>
telco <local>
tomli_loads <local>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[project]
name = "pyperformance_stdlib_startup"
requires-python = ">=3.10"
dependencies = []
urls = {repository = "https://github.com/python/pyperformance"}
dynamic = ["version"]

[tool.pyperformance]
name = "stdlib_startup"
tags = "startup"
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import os
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import os
"""
Measures the time it takes to import all of the modules in the stdlib.
This benchmark is expected to change as the stdlib changes, so is not
suitable for measuring compilation time.
"""
import os

import sys
import subprocess
import tempfile

import pyperf

if __name__ == "__main__":
runner = pyperf.Runner(values=10)

runner.metadata['description'] = "Performance of importing standard library modules"
args = runner.parse_args()

with tempfile.TemporaryDirectory() as tmp:
main = os.path.join(tmp, "main.py")
with open(main, "w") as f:
f.write("""
import importlib
import sys
for m in sys.stdlib_module_names:
if m in {"antigravity", "this"}:
continue
try:
importlib.import_module(m)
except ImportError:
pass
""")
command = [sys.executable, main]
runner.bench_command('stdlib_startup', command)
Loading