22Benchmarking and performance tests.
33"""
44import pytest
5-
6- from pluggy import _MultiCall , HookImpl
7- from pluggy import HookspecMarker , HookimplMarker
8-
5+ from pluggy import _MultiCall , HookImpl , HookspecMarker , HookimplMarker
96
107hookspec = HookspecMarker ("example" )
118hookimpl = HookimplMarker ("example" )
@@ -19,40 +16,35 @@ def MC(methods, kwargs, firstresult=False):
1916 return _MultiCall (hookfuncs , kwargs , {"firstresult" : firstresult })
2017
2118
22- @hookimpl (hookwrapper = True )
23- def m1 (arg1 , arg2 , arg3 ):
24- yield
25-
26-
2719@hookimpl
28- def m2 (arg1 , arg2 , arg3 ):
20+ def hook (arg1 , arg2 , arg3 ):
2921 return arg1 , arg2 , arg3
3022
3123
3224@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 ):
3926 yield
4027
4128
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 )]
4435
4536
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 )]
4943
5044
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 ()
5447
5548
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