[FR] Register function using macro, write the loop part only
- Dominant language
- C++
- Stars
- 10.4k
- Forks
- 1.8k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 8
Description
Hi. I was thinking about a way to register a test by writing as little as possible boilerplate and looking for something like:
```cpp
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.
```cpp
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.
```cpp
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?
Contributor guide
Assessment
This issue has not been assessed yet.