Skip to content

Commit d2cd246

Browse files
authored
Clarify the difference between BENCHMARK_TEMPLATE_F and BENCHMARK_TEMPLATE_DEFINE_F + BENCHMARK_REGISTER_F (#1815)
* Clarify BENCHMARK_REGISTER_F Add comments highlighting the difference between `BENCHMARK_TEMPLATE_F` and `BENCHMARK_TEMPLATE_DEFINE_F`, mirroring those of `BENCHMARK_F ` and `BENCHMARK_DEFINE_F`. * More informative comments. * Update user_guide.md
1 parent 38df9da commit d2cd246

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

docs/user_guide.md

+10-5
Original file line numberDiff line numberDiff line change
@@ -624,20 +624,22 @@ public:
624624
}
625625
};
626626
627+
// Defines and registers `FooTest` using the class `MyFixture`.
627628
BENCHMARK_F(MyFixture, FooTest)(benchmark::State& st) {
628629
for (auto _ : st) {
629630
...
630631
}
631632
}
632633
634+
// Only defines `BarTest` using the class `MyFixture`.
633635
BENCHMARK_DEFINE_F(MyFixture, BarTest)(benchmark::State& st) {
634636
for (auto _ : st) {
635637
...
636638
}
637639
}
638-
/* BarTest is NOT registered */
640+
// `BarTest` is NOT registered.
639641
BENCHMARK_REGISTER_F(MyFixture, BarTest)->Threads(2);
640-
/* BarTest is now registered */
642+
// `BarTest` is now registered.
641643
```
642644

643645
### Templated Fixtures
@@ -653,19 +655,22 @@ For example:
653655
template<typename T>
654656
class MyFixture : public benchmark::Fixture {};
655657

658+
// Defines and registers `IntTest` using the class template `MyFixture<int>`.
656659
BENCHMARK_TEMPLATE_F(MyFixture, IntTest, int)(benchmark::State& st) {
657660
for (auto _ : st) {
658661
...
659662
}
660663
}
661664

665+
// Only defines `DoubleTest` using the class template `MyFixture<double>`.
662666
BENCHMARK_TEMPLATE_DEFINE_F(MyFixture, DoubleTest, double)(benchmark::State& st) {
663667
for (auto _ : st) {
664668
...
665669
}
666670
}
667-
671+
// `DoubleTest` is NOT registered.
668672
BENCHMARK_REGISTER_F(MyFixture, DoubleTest)->Threads(2);
673+
// `DoubleTest` is now registered.
669674
```
670675
671676
<a name="custom-counters" />
@@ -1012,11 +1017,11 @@ in any way. `<expr>` may even be removed entirely when the result is already
10121017
known. For example:
10131018
10141019
```c++
1015-
/* Example 1: `<expr>` is removed entirely. */
1020+
// Example 1: `<expr>` is removed entirely.
10161021
int foo(int x) { return x + 42; }
10171022
while (...) DoNotOptimize(foo(0)); // Optimized to DoNotOptimize(42);
10181023
1019-
/* Example 2: Result of '<expr>' is only reused */
1024+
// Example 2: Result of '<expr>' is only reused.
10201025
int bar(int) __attribute__((const));
10211026
while (...) DoNotOptimize(bar(0)); // Optimized to:
10221027
// int __result__ = bar(0);

0 commit comments

Comments
 (0)