ionelmc / pytest-benchmark

py.test fixture for benchmarking code
BSD 2-Clause "Simplified" License
1.23k stars 119 forks source link

pytest_benchmark_group_stats not working as expected #201

Open swethmandava opened 3 years ago

swethmandava commented 3 years ago
@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?

ionelmc commented 3 years ago

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.

swethmandava commented 3 years ago

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.