diff --git a/pyperformance/data-files/benchmarks/MANIFEST b/pyperformance/data-files/benchmarks/MANIFEST index 9d1f6c8c..35777453 100644 --- a/pyperformance/data-files/benchmarks/MANIFEST +++ b/pyperformance/data-files/benchmarks/MANIFEST @@ -92,6 +92,7 @@ sqlglot_v2_parse sqlglot_v2_transpile sqlglot_v2_optimize sqlite_synth +stdlib_startup sympy telco tomli_loads diff --git a/pyperformance/data-files/benchmarks/bm_stdlib_startup/pyproject.toml b/pyperformance/data-files/benchmarks/bm_stdlib_startup/pyproject.toml new file mode 100644 index 00000000..35f520bd --- /dev/null +++ b/pyperformance/data-files/benchmarks/bm_stdlib_startup/pyproject.toml @@ -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" diff --git a/pyperformance/data-files/benchmarks/bm_stdlib_startup/requirements.txt b/pyperformance/data-files/benchmarks/bm_stdlib_startup/requirements.txt new file mode 100644 index 00000000..e69de29b diff --git a/pyperformance/data-files/benchmarks/bm_stdlib_startup/run_benchmark.py b/pyperformance/data-files/benchmarks/bm_stdlib_startup/run_benchmark.py new file mode 100644 index 00000000..a0e3057d --- /dev/null +++ b/pyperformance/data-files/benchmarks/bm_stdlib_startup/run_benchmark.py @@ -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 +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)