Skip to content

Commit 6babb6e

Browse files
author
Tyler Goodlet
committed
Add a baseline set of _MultiCall performance tests
This begins an effort to incorporate run-time speed tests using `pytest-benchmark`. This initial test set audits the `_MultiCall` loop with hookimpls, hookwrappers and the combination of both. The intention is to eventually have a reliable set of tests which enable making core component modifications without disrupting performance as per #37.
1 parent 4a2478c commit 6babb6e

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

testing/benchmark.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
"""
2+
Benchmarking and performance tests.
3+
"""
4+
import pytest
5+
6+
from pluggy import _MultiCall, HookImpl
7+
from pluggy import HookspecMarker, HookimplMarker
8+
9+
10+
hookspec = HookspecMarker("example")
11+
hookimpl = HookimplMarker("example")
12+
13+
14+
def MC(methods, kwargs, firstresult=False):
15+
hookfuncs = []
16+
for method in methods:
17+
f = HookImpl(None, "<temp>", method, method.example_impl)
18+
hookfuncs.append(f)
19+
return _MultiCall(hookfuncs, kwargs, {"firstresult": firstresult})
20+
21+
22+
@hookimpl(hookwrapper=True)
23+
def m1(arg1, arg2, arg3):
24+
yield
25+
26+
27+
@hookimpl
28+
def m2(arg1, arg2, arg3):
29+
return arg1, arg2, arg3
30+
31+
32+
@hookimpl(hookwrapper=True)
33+
def w1(arg1, arg2, arg3):
34+
yield
35+
36+
37+
@hookimpl(hookwrapper=True)
38+
def w2(arg1, arg2, arg3):
39+
yield
40+
41+
42+
def inner_exec(methods):
43+
return MC(methods, {'arg1': 1, 'arg2': 2, 'arg3': 3}).execute()
44+
45+
46+
@pytest.mark.benchmark
47+
def test_hookimpls_speed(benchmark):
48+
benchmark(inner_exec, [m1, m2])
49+
50+
51+
@pytest.mark.benchmark
52+
def test_hookwrappers_speed(benchmark):
53+
benchmark(inner_exec, [w1, w2])
54+
55+
56+
@pytest.mark.benchmark
57+
def test_impls_and_wrappers_speed(benchmark):
58+
benchmark(inner_exec, [m1, m2, w1, w2])

0 commit comments

Comments
 (0)