Skip to content

Commit 8933947

Browse files
committed
docs: add an example on measuring import times
1 parent c92304c commit 8933947

File tree

5 files changed

+23
-1
lines changed

5 files changed

+23
-1
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ float_to_top = true
118118
[tool.pytest.ini_options]
119119
addopts = "--ignore=tests/benchmarks --ignore=tests/examples --ignore=tests/benchmarks/TheAlgorithms"
120120
filterwarnings = ["ignore::DeprecationWarning:pytest_benchmark.utils.*:"]
121-
pythonpath = ["tests/benchmarks/TheAlgorithms", "./scripts"]
121+
pythonpath = ["tests/benchmarks/TheAlgorithms", "./scripts", "tests/benchmarks"]
122122

123123
[tool.coverage.run]
124124
branch = true

tests/benchmarks/test_bench_imports/__init__.py

Whitespace-only changes.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Fake import initialization payload
2+
for i in range(10000):
3+
pass
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Depends on module_a.py
2+
from . import module_a
3+
# Fake import initialization payload
4+
for i in range(10000):
5+
pass
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import importlib
2+
import sys
3+
import time
4+
import pytest
5+
from unittest import mock
6+
7+
@pytest.mark.parametrize("mod_name", [".module_a", ".module_b"])
8+
def test_bench_module_import(benchmark, mod_name):
9+
@benchmark
10+
def _():
11+
with mock.patch("sys.modules", {}):
12+
importlib.import_module(mod_name, "test_bench_imports")
13+
14+

0 commit comments

Comments
 (0)