benchmarks: remove more boilerplate.
Many of our benchmarks are basically just "call one function with a
fixed argument". We don't need to keep repeating all the boilerplate for
that.
This also ensures we don't forget the benchmark::DoNotOptimize, which --
in addition to being a good idea in general -- specifically solves the
problem with gettid benchmark and provides a more accurate result by
removing the indirection through a function pointer.
Test: ran benchmarks
Change-Id: Id67535243678cd0d48f51cf25141e2040da9af03
diff --git a/benchmarks/util.h b/benchmarks/util.h
index 0813acc..ef4892d 100644
--- a/benchmarks/util.h
+++ b/benchmarks/util.h
@@ -41,6 +41,13 @@
#define BIONIC_BENCHMARK_WITH_ARG(n, arg) \
int _bionic_benchmark_##n __attribute__((unused)) = EmplaceBenchmark(std::string(#n), reinterpret_cast<benchmark_func_t>(n), arg)
+#define BIONIC_TRIVIAL_BENCHMARK(__name, __expression) \
+ static void __name(benchmark::State& state) { \
+ for (auto _ : state) { \
+ benchmark::DoNotOptimize(__expression); \
+ } \
+ } \
+ BIONIC_BENCHMARK(__name)
constexpr auto KB = 1024;