Skip to content
Merged
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 @@ -92,6 +92,7 @@ sqlglot_v2_parse <local:sqlglot_v2>
sqlglot_v2_transpile <local:sqlglot_v2>
sqlglot_v2_optimize <local:sqlglot_v2>
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,34 @@
"""
Measures the time it takes to import all the modules (excluding those with
import side effects) in the stdlib.

This benchmark is expected to change as the stdlib changes, so it is not
suitable for measuring compilation time.
"""

import os
Comment thread
StanFromIreland marked this conversation as resolved.
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")
modules_to_import = sorted(sys.stdlib_module_names - {'antigravity', 'this'})
with open(main, 'w', encoding='utf-8') as f:
for module in modules_to_import:
f.write(f"""
try:
import {module}
except ImportError:
pass
""")
command = [sys.executable, main]
runner.bench_command('stdlib_startup', command)
Loading