2
2
Benchmarking and performance tests.
3
3
"""
4
4
import pytest
5
-
6
- from pluggy import _MultiCall , HookImpl
7
- from pluggy import HookspecMarker , HookimplMarker
8
-
5
+ from pluggy import _MultiCall , HookImpl , HookspecMarker , HookimplMarker
9
6
10
7
hookspec = HookspecMarker ("example" )
11
8
hookimpl = HookimplMarker ("example" )
@@ -19,40 +16,35 @@ def MC(methods, kwargs, firstresult=False):
19
16
return _MultiCall (hookfuncs , kwargs , {"firstresult" : firstresult })
20
17
21
18
22
- @hookimpl (hookwrapper = True )
23
- def m1 (arg1 , arg2 , arg3 ):
24
- yield
25
-
26
-
27
19
@hookimpl
28
- def m2 (arg1 , arg2 , arg3 ):
20
+ def hook (arg1 , arg2 , arg3 ):
29
21
return arg1 , arg2 , arg3
30
22
31
23
32
24
@hookimpl (hookwrapper = True )
33
- def w1 (arg1 , arg2 , arg3 ):
34
- yield
35
-
36
-
37
- @hookimpl (hookwrapper = True )
38
- def w2 (arg1 , arg2 , arg3 ):
25
+ def wrapper (arg1 , arg2 , arg3 ):
39
26
yield
40
27
41
28
42
- def inner_exec (methods ):
43
- return MC (methods , {'arg1' : 1 , 'arg2' : 2 , 'arg3' : 3 }).execute ()
29
+ @pytest .fixture (
30
+ params = [0 , 1 , 10 , 100 ],
31
+ ids = "hooks={}" .format ,
32
+ )
33
+ def hooks (request ):
34
+ return [hook for i in range (request .param )]
44
35
45
36
46
- @pytest .mark .benchmark
47
- def test_hookimpls_speed (benchmark ):
48
- benchmark (inner_exec , [m1 , m2 ])
37
+ @pytest .fixture (
38
+ params = [0 , 1 , 10 , 100 ],
39
+ ids = "wrappers={}" .format ,
40
+ )
41
+ def wrappers (request ):
42
+ return [wrapper for i in range (request .param )]
49
43
50
44
51
- @pytest .mark .benchmark
52
- def test_hookwrappers_speed (benchmark ):
53
- benchmark (inner_exec , [w1 , w2 ])
45
+ def inner_exec (methods ):
46
+ return MC (methods , {'arg1' : 1 , 'arg2' : 2 , 'arg3' : 3 }).execute ()
54
47
55
48
56
- @pytest .mark .benchmark
57
- def test_impls_and_wrappers_speed (benchmark ):
58
- benchmark (inner_exec , [m1 , m2 , w1 , w2 ])
49
+ def test_hook_and_wrappers_speed (benchmark , hooks , wrappers ):
50
+ benchmark (inner_exec , hooks + wrappers )
0 commit comments