Skip to content

Commit

Permalink
Don't include setup overhead in benchmark measurement
Browse files Browse the repository at this point in the history
  • Loading branch information
bluetech committed Jun 29, 2020
1 parent bc79719 commit d22672d
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions testing/benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,11 @@
from pluggy.hooks import HookImpl
from pluggy.callers import _multicall


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


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


@hookimpl
def hook(arg1, arg2, arg3):
return arg1, arg2, arg3
Expand All @@ -38,9 +31,14 @@ def wrappers(request):
return [wrapper for i in range(request.param)]


def inner_exec(methods):
return MC(methods, {"arg1": 1, "arg2": 2, "arg3": 3})


def test_hook_and_wrappers_speed(benchmark, hooks, wrappers):
benchmark(inner_exec, hooks + wrappers)
def setup():
hook_impls = []
for method in hooks + wrappers:
f = HookImpl(None, "<temp>", method, method.example_impl)
hook_impls.append(f)
caller_kwargs = {"arg1": 1, "arg2": 2, "arg3": 3}
firstresult = False
return (hook_impls, caller_kwargs, firstresult), {}

benchmark.pedantic(_multicall, setup=setup)

0 comments on commit d22672d

Please sign in to comment.