Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#include <type_traits>
#include "testing/benchmark.h"
#include "testing/gmock.h"
#include "testing/gunit.h"
#include "absl/flags/flag.h"
#include "absl/time/time.h"
// Updater threads + reverse frequency 1/128.
#define BENCHMARK_FLAG(func) BENCHMARK(func)->ThreadRange(1, 32)
template <class T, class Flag>
static void BM_ManyReadersFlag(benchmark::State& state) {
static_assert(std::is_trivially_copyable<T>::value, "!!!");
// Many readers.
for (auto _ : state) {
testing::DoNotOptimize(absl::GetFlag(*Flag{}()));
}
}
#define FLAG_BENCHMARK(type, name, default_value) \
ABSL_FLAG(type, name, default_value, ""); \
struct FLAG_##name { \
inline auto operator()() const { return &FLAGS_##name; } \
}; \
BENCHMARK_FLAG((BM_ManyReadersFlag<type, FLAG_##name>))
using absl::Duration;
FLAG_BENCHMARK(Duration, dur, absl::InfiniteDuration());
FLAG_BENCHMARK(bool, b, true);
FLAG_BENCHMARK(short, s, 1);
FLAG_BENCHMARK(int, i32, 1);
FLAG_BENCHMARK(int64_t, i64, 1);
FLAG_BENCHMARK(long, l, 10);
FLAG_BENCHMARK(double, d, 0.0);
FLAG_BENCHMARK(float, f, 0.f);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.