Skip to content

[FR] Register function using macro, write the loop part only #1950

@GitSparTV

Description

@GitSparTV

Hi. I was thinking about a way to register a test by writing as little as possible boilerplate and looking for something like:

BENCHMARK_SIMPLE(TestName) {
    // Benchmark subject
}

The downside that you have to write second } to at least end the function.
And as with BENCHMARK_F, you can't call methods afterwards.

BENCHMARK_DEFINE_SIMPLE(TestName) {
    // Benchmark subject
}

BENCHMARK_REGISTER_SIMPLE(TestName)->Setup(...)->Teardown(...);

Now we can call methods, but we have same thing as with BENCHMARK_DEFINE_F: you have to spell the name of the test twice. 100% no copypasta :smiling:

If we pass do as BENCHMARK_CAPTURE we will have an almost perfect solution.

BENCHMARK_SIMPLE_CAPTURE([](benchmark::State& state){

})->Setup(...)->Teardown(...);

But we still have state argument written out. Dang it. We could remove it, but then we won't be able to get/set data from/to state.

I'll leave it as it for now, what do you think? Is it useful and is possible?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions