From d1f7d433e7b0180621fc427606f4f81ef128beeb Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Wed, 5 Jul 2017 00:13:01 -0400 Subject: [PATCH] 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. --- testing/test_multicall.py | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/testing/test_multicall.py b/testing/test_multicall.py index 7aff8c33..a8874eb2 100644 --- a/testing/test_multicall.py +++ b/testing/test_multicall.py @@ -22,7 +22,7 @@ def MC(methods, kwargs, firstresult=False): for method in methods: f = HookImpl(None, "", method, method.example_impl) hookfuncs.append(f) - return _MultiCall(hookfuncs, kwargs, {"firstresult": firstresult}) + return _MultiCall(hookfuncs, kwargs, firstresult=firstresult) def test_call_passing(): @@ -197,3 +197,40 @@ def m2(): with pytest.raises(exc): MC([m2, m1], {}).execute() assert l == ["m1 init", "m1 finish"] + + +@hookimpl(hookwrapper=True) +def m1(arg1, arg2, arg3): + yield + + +@hookimpl +def m2(arg1, arg2, arg3): + return arg1, arg2, arg3 + + +@hookimpl(hookwrapper=True) +def w1(arg1, arg2, arg3): + yield + + +@hookimpl(hookwrapper=True) +def w2(arg1, arg2, arg3): + yield + + +def inner_exec(methods): + return MC(methods, {'arg1': 1, 'arg2': 2, 'arg3': 3}).execute() + +@pytest.mark.benchmark +def test_hookimpls_speed(benchmark): + benchmark(inner_exec, [m1, m2]) + + +@pytest.mark.benchmark +def test_hookwrapper_speed(benchmark): + benchmark(inner_exec, [w1, w2]) + +@pytest.mark.benchmark +def test_impl_and_wrapper_speed(benchmark): + benchmark(inner_exec, [m1, m2, w1, w2])