From b1b8a37b2592ad4cd1accdd44a0d0913c9b00e3a Mon Sep 17 00:00:00 2001 From: hauntsaninja Date: Sun, 19 May 2024 15:20:14 -0400 Subject: [PATCH 1/2] 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. --- pyperformance/data-files/benchmarks/MANIFEST | 1 + .../bm_stdlib_startup/pyproject.toml | 10 +++++++ .../bm_stdlib_startup/requirements.txt | 0 .../bm_stdlib_startup/run_benchmark.py | 29 +++++++++++++++++++ 4 files changed, 40 insertions(+) create mode 100644 pyperformance/data-files/benchmarks/bm_stdlib_startup/pyproject.toml create mode 100644 pyperformance/data-files/benchmarks/bm_stdlib_startup/requirements.txt create mode 100644 pyperformance/data-files/benchmarks/bm_stdlib_startup/run_benchmark.py diff --git a/pyperformance/data-files/benchmarks/MANIFEST b/pyperformance/data-files/benchmarks/MANIFEST index 3210b97f..19c9dc24 100644 --- a/pyperformance/data-files/benchmarks/MANIFEST +++ b/pyperformance/data-files/benchmarks/MANIFEST @@ -81,6 +81,7 @@ sqlglot_parse sqlglot_transpile sqlglot_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..1ccbc3cf --- /dev/null +++ b/pyperformance/data-files/benchmarks/bm_stdlib_startup/pyproject.toml @@ -0,0 +1,10 @@ +[project] +name = "pyperformance_stdlib_startup" +requires-python = ">=3.8" +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..21f7269f --- /dev/null +++ b/pyperformance/data-files/benchmarks/bm_stdlib_startup/run_benchmark.py @@ -0,0 +1,29 @@ +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) From 7ed61dc780fcda1a0a5a13e7e0d09299a1d28bf1 Mon Sep 17 00:00:00 2001 From: hauntsaninja Date: Mon, 20 May 2024 01:29:47 -0400 Subject: [PATCH 2/2] . --- .../data-files/benchmarks/bm_stdlib_startup/pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyperformance/data-files/benchmarks/bm_stdlib_startup/pyproject.toml b/pyperformance/data-files/benchmarks/bm_stdlib_startup/pyproject.toml index 1ccbc3cf..35f520bd 100644 --- a/pyperformance/data-files/benchmarks/bm_stdlib_startup/pyproject.toml +++ b/pyperformance/data-files/benchmarks/bm_stdlib_startup/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "pyperformance_stdlib_startup" -requires-python = ">=3.8" +requires-python = ">=3.10" dependencies = [] urls = {repository = "https://github.com/python/pyperformance"} dynamic = ["version"]