Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
GitSparTV opened this issue Mar 18, 2025 · 0 comments
Open

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

GitSparTV opened this issue Mar 18, 2025 · 0 comments

Comments

@GitSparTV
Copy link

GitSparTV commented Mar 18, 2025

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant