pytest-benchmark icon indicating copy to clipboard operation
pytest-benchmark copied to clipboard

pytest_benchmark_group_stats not working as expected

Open swethmandava opened this issue 3 years ago • 2 comments

@pytest.mark.hookwrapper
def pytest_benchmark_group_stats(config, benchmarks, group_by):
    result = defaultdict(list)
    for bench in benchmarks:
        result[bench.group].append(bench)
    return result.items()

@pytest.mark.benchmark(group='search')
@pytest.mark.parametrize("query", test_queries)
def test_benchmark_search(benchmark, query):
    benchmark(some_func, query)

when called with pytest test_benchmark.py --benchmark-json=benchmark.json returns a list of timings for each parameterized version. I'd want it to group all parameterized calls into a single output called "search". Is that possible?

swethmandava avatar Apr 28 '21 17:04 swethmandava

You'd like to average all the benchmark from the 'search' group together?

It could be possible if you do the averaging yourself and mess with the stats a bit...

I would like to understand a bit what's the purpose here.

Ref #166.

ionelmc avatar Apr 29 '21 07:04 ionelmc

I can think of some_func as a function which takes time T dependent on the parameter. I'd want to benchmark this function to get stats for a variety of parameters that are relevant to the user. So if i have 10 relevant parameters - I want to collect stats (mean/median) for these 10 parameters with the benchmark function. instead of mean/mean for each parameter.

swethmandava avatar Apr 29 '21 16:04 swethmandava