1""" 2Benchmarking and performance tests. 3""" 4import pytest 5from pluggy import HookspecMarker, HookimplMarker 6from pluggy.hooks import HookImpl 7from pluggy.callers import _multicall, _legacymulticall 8 9hookspec = HookspecMarker("example") 10hookimpl = HookimplMarker("example") 11 12 13def MC(methods, kwargs, callertype, firstresult=False): 14 hookfuncs = [] 15 for method in methods: 16 f = HookImpl(None, "<temp>", method, method.example_impl) 17 hookfuncs.append(f) 18 return callertype(hookfuncs, kwargs, firstresult=firstresult) 19 20 21@hookimpl 22def hook(arg1, arg2, arg3): 23 return arg1, arg2, arg3 24 25 26@hookimpl(hookwrapper=True) 27def wrapper(arg1, arg2, arg3): 28 yield 29 30 31@pytest.fixture(params=[10, 100], ids="hooks={}".format) 32def hooks(request): 33 return [hook for i in range(request.param)] 34 35 36@pytest.fixture(params=[10, 100], ids="wrappers={}".format) 37def wrappers(request): 38 return [wrapper for i in range(request.param)] 39 40 41@pytest.fixture(params=[_multicall, _legacymulticall], ids=lambda item: item.__name__) 42def callertype(request): 43 return request.param 44 45 46def inner_exec(methods, callertype): 47 return MC(methods, {"arg1": 1, "arg2": 2, "arg3": 3}, callertype) 48 49 50def test_hook_and_wrappers_speed(benchmark, hooks, wrappers, callertype): 51 benchmark(inner_exec, hooks + wrappers, callertype) 52