This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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