Skip to content

Commit c83cdb4

Browse files
authored
Merge pull request #326 from python/feature/pytest-perf
Use pytest-perf to capture performance expectations and regressions
2 parents 14f2a68 + 6dfb530 commit c83cdb4

File tree

5 files changed

+40
-55
lines changed

5 files changed

+40
-55
lines changed

.coveragerc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ omit =
55
tests/*
66
prepare/*
77
*/_itertools.py
8+
exercises.py
89

910
[report]
1011
show_missing = True

.github/workflows/main.yml

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,6 @@ jobs:
2424
- name: Run tests
2525
run: tox
2626

27-
benchmark:
28-
runs-on: ubuntu-latest
29-
steps:
30-
- uses: actions/checkout@v2
31-
- name: Setup Python
32-
uses: actions/setup-python@v2
33-
with:
34-
python-version: 3.9
35-
- name: Install tox
36-
run: |
37-
python -m pip install tox
38-
- name: Run benchmarks
39-
run: tox
40-
env:
41-
TOXENV: perf{,-ref}
42-
4327
diffcov:
4428
runs-on: ubuntu-latest
4529
steps:

exercises.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
from pytest_perf.deco import extras
2+
3+
4+
@extras('perf')
5+
def discovery_perf():
6+
"discovery"
7+
import importlib_metadata # end warmup
8+
9+
importlib_metadata.distribution('ipython')
10+
11+
12+
def entry_points_perf():
13+
"entry_points()"
14+
import importlib_metadata # end warmup
15+
16+
importlib_metadata.entry_points()
17+
18+
19+
@extras('perf')
20+
def cached_distribution_perf():
21+
"cached distribution"
22+
import importlib_metadata
23+
24+
importlib_metadata.distribution('ipython') # end warmup
25+
importlib_metadata.distribution('ipython')
26+
27+
28+
@extras('perf')
29+
def uncached_distribution_perf():
30+
"uncached distribution"
31+
import importlib
32+
import importlib_metadata
33+
34+
# end warmup
35+
importlib.invalidate_caches()
36+
importlib_metadata.distribution('ipython')

setup.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ testing =
5151
pep517
5252
pyfakefs
5353
flufl.flake8
54+
pytest-perf >= 0.9.2
5455

5556
docs =
5657
# upstream

tox.ini

Lines changed: 2 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ toxworkdir={env:TOX_WORK_DIR:.tox}
1010
deps =
1111
commands =
1212
pytest {posargs}
13+
passenv =
14+
HOME
1315
usedevelop = True
1416
extras = testing
1517
setenv =
@@ -33,45 +35,6 @@ commands =
3335
diff-cover coverage.xml --compare-branch=origin/main --html-report diffcov.html
3436
diff-cover coverage.xml --compare-branch=origin/main --fail-under=100
3537

36-
[perf]
37-
deps =
38-
ipython
39-
pyperf
40-
path
41-
commands =
42-
python -c "import path; path.Path('{env:SCOPE}.json').remove_p()"
43-
44-
python -m pyperf timeit --name discovery --append {env:SCOPE}.json -s 'import importlib_metadata' 'importlib_metadata.distribution("ipython")'
45-
46-
python -m pyperf timeit --name 'entry_points()' --append {env:SCOPE}.json -s 'import importlib_metadata' 'importlib_metadata.entry_points()'
47-
48-
python -m pyperf timeit --name 'cached distribution' --append {env:SCOPE}.json -s 'import importlib_metadata; importlib_metadata.distribution("ipython")' 'importlib_metadata.distribution("ipython")'
49-
50-
python -m pyperf timeit --name 'uncached distribution' --append {env:SCOPE}.json -s 'import importlib, importlib_metadata' 'importlib.invalidate_caches(); importlib_metadata.distribution("ipython")'
51-
52-
[testenv:perf]
53-
use_develop = False
54-
# change dir to avoid picking up local package.
55-
changedir = {toxworkdir}
56-
setenv =
57-
SCOPE = local
58-
deps = {[perf]deps}
59-
commands = {[perf]commands}
60-
61-
[testenv:perf-ref]
62-
# compare perf results to the main branch
63-
skip_install = True
64-
# change dir to avoid picking up local package.
65-
changedir = {toxworkdir}
66-
setenv =
67-
SCOPE = main
68-
deps =
69-
{[perf]deps}
70-
git+https://github.com/python/importlib_metadata
71-
commands =
72-
{[perf]commands}
73-
python -m pyperf compare_to --verbose main.json local.json --table
74-
7538
[testenv:release]
7639
skip_install = True
7740
deps =

0 commit comments

Comments
 (0)