Skip to content

Commit

Permalink
Parametrize over legacy versus new multicall types
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyler Goodlet committed Jul 10, 2017
1 parent 09d7589 commit 21fd6c4
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions testing/benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@
Benchmarking and performance tests.
"""
import pytest
from pluggy import _MultiCall, HookImpl, HookspecMarker, HookimplMarker
from pluggy import (_MultiCall, _LegacyMultiCall, HookImpl, HookspecMarker,
HookimplMarker)

hookspec = HookspecMarker("example")
hookimpl = HookimplMarker("example")


def MC(methods, kwargs, firstresult=False):
def MC(methods, kwargs, callertype, firstresult=False):
hookfuncs = []
for method in methods:
f = HookImpl(None, "<temp>", method, method.example_impl)
hookfuncs.append(f)
return _MultiCall(hookfuncs, kwargs, {"firstresult": firstresult})
return callertype(hookfuncs, kwargs, {"firstresult": firstresult})


@hookimpl
Expand Down Expand Up @@ -42,9 +43,17 @@ def wrappers(request):
return [wrapper for i in range(request.param)]


def inner_exec(methods):
return MC(methods, {'arg1': 1, 'arg2': 2, 'arg3': 3}).execute()
@pytest.fixture(
params=[_MultiCall, _LegacyMultiCall],
ids=lambda item: item.__name__
)
def callertype(request):
return request.param


def inner_exec(methods, callertype):
return MC(methods, {'arg1': 1, 'arg2': 2, 'arg3': 3}, callertype).execute()


def test_hook_and_wrappers_speed(benchmark, hooks, wrappers):
benchmark(inner_exec, hooks + wrappers)
def test_hook_and_wrappers_speed(benchmark, hooks, wrappers, callertype):
benchmark(inner_exec, hooks + wrappers, callertype)

0 comments on commit 21fd6c4

Please sign in to comment.