bench: bench.h fixes and improvements

This commit is contained in:
Jon Atack 2021-06-20 17:50:39 +02:00
parent 965e937434
commit 10f4ce2078
No known key found for this signature in database
GPG key ID: 4F5721B3D0E3921D

View file

@ -18,16 +18,19 @@
/* /*
* Usage: * Usage:
static void CODE_TO_TIME(benchmark::Bench& bench) static void NameOfYourBenchmarkFunction(benchmark::Bench& bench)
{ {
... do any setup needed... ...do any setup needed...
nanobench::Config().run([&] {
... do stuff you want to time... bench.run([&] {
...do stuff you want to time; refer to src/bench/nanobench.h
for more information and the options that can be passed here...
}); });
... do any cleanup needed...
...do any cleanup needed...
} }
BENCHMARK(CODE_TO_TIME); BENCHMARK(NameOfYourBenchmarkFunction);
*/ */
@ -55,7 +58,8 @@ public:
static void RunAll(const Args& args); static void RunAll(const Args& args);
}; };
} } // namespace benchmark
// BENCHMARK(foo) expands to: benchmark::BenchRunner bench_11foo("foo", foo); // BENCHMARK(foo) expands to: benchmark::BenchRunner bench_11foo("foo", foo);
#define BENCHMARK(n) \ #define BENCHMARK(n) \
benchmark::BenchRunner PASTE2(bench_, PASTE2(__LINE__, n))(STRINGIZE(n), n); benchmark::BenchRunner PASTE2(bench_, PASTE2(__LINE__, n))(STRINGIZE(n), n);