Go to the documentation of this file.
21 #include "absl/flags/flag.h"
22 #include "absl/flags/marshalling.h"
23 #include "absl/flags/parse.h"
24 #include "absl/flags/reflection.h"
25 #include "absl/strings/string_view.h"
26 #include "absl/time/time.h"
27 #include "absl/types/optional.h"
28 #include "benchmark/benchmark.h"
32 using VectorOfStrings = std::vector<std::string>;
39 struct OptionalInt : AbslOptionalInt {
40 using AbslOptionalInt::AbslOptionalInt;
58 struct OptionalString : AbslOptionalString {
59 using AbslOptionalString::AbslOptionalString;
87 #define BENCHMARKED_TYPES(A) \
104 #define REPLICATE_0(A, T, name, index) A(T, name, index)
105 #define REPLICATE_1(A, T, name, index) \
106 REPLICATE_0(A, T, name, index##0) REPLICATE_0(A, T, name, index##1)
107 #define REPLICATE_2(A, T, name, index) \
108 REPLICATE_1(A, T, name, index##0) REPLICATE_1(A, T, name, index##1)
109 #define REPLICATE_3(A, T, name, index) \
110 REPLICATE_2(A, T, name, index##0) REPLICATE_2(A, T, name, index##1)
111 #define REPLICATE_4(A, T, name, index) \
112 REPLICATE_3(A, T, name, index##0) REPLICATE_3(A, T, name, index##1)
113 #define REPLICATE_5(A, T, name, index) \
114 REPLICATE_4(A, T, name, index##0) REPLICATE_4(A, T, name, index##1)
115 #define REPLICATE_6(A, T, name, index) \
116 REPLICATE_5(A, T, name, index##0) REPLICATE_5(A, T, name, index##1)
117 #define REPLICATE_7(A, T, name, index) \
118 REPLICATE_6(A, T, name, index##0) REPLICATE_6(A, T, name, index##1)
119 #define REPLICATE_8(A, T, name, index) \
120 REPLICATE_7(A, T, name, index##0) REPLICATE_7(A, T, name, index##1)
121 #define REPLICATE_9(A, T, name, index) \
122 REPLICATE_8(A, T, name, index##0) REPLICATE_8(A, T, name, index##1)
123 #if defined(_MSC_VER)
124 #define REPLICATE(A, T, name) \
125 REPLICATE_7(A, T, name, 0) REPLICATE_7(A, T, name, 1)
126 #define SINGLE_FLAG(T) FLAGS_##T##_flag_00000000
128 #define REPLICATE(A, T, name) \
129 REPLICATE_9(A, T, name, 0) REPLICATE_9(A, T, name, 1)
130 #define SINGLE_FLAG(T) FLAGS_##T##_flag_0000000000
132 #define REPLICATE_ALL(A, T, name) \
133 REPLICATE_9(A, T, name, 0) REPLICATE_9(A, T, name, 1)
135 #define COUNT(T, name, index) +1
138 #if defined(__clang__) && defined(__linux__)
143 #pragma clang section data = ".benchmark_flags"
145 #define DEFINE_FLAG(T, name, index) ABSL_FLAG(T, name##_##index, {}, "");
146 #define FLAG_DEF(T) REPLICATE(DEFINE_FLAG, T, T##_flag);
148 #if defined(__clang__) && defined(__linux__)
149 #pragma clang section data = ""
153 #define BLOAT_FLAG(_unused1, _unused2, index) \
154 ABSL_FLAG(int, bloat_flag_##index, 0, "");
159 #define FLAG_PTR(T, name, index) &FLAGS_##name##_##index,
160 #define FLAG_PTR_ARR(T) \
161 static constexpr absl::Flag<T>* FlagPtrs_##T[] = { \
162 REPLICATE(FLAG_PTR, T, T##_flag)};
165 #define BM_SingleGetFlag(T) \
166 void BM_SingleGetFlag_##T(benchmark::State& state) { \
167 for (auto _ : state) { \
168 benchmark::DoNotOptimize(absl::GetFlag(SINGLE_FLAG(T))); \
171 BENCHMARK(BM_SingleGetFlag_##T)->ThreadRange(1, 16);
175 template <
typename T>
180 struct Accumulator<String> {
184 struct Accumulator<VectorOfStrings> {
188 struct Accumulator<OptionalInt> {
192 struct Accumulator<OptionalString> {
196 struct Accumulator<UDT> {
200 template <
typename T>
201 void Accumulate(
typename Accumulator<T>::type&
a,
const T&
f) {
204 void Accumulate(
bool&
a,
bool f) {
a =
a ||
f; }
206 void Accumulate(
size_t&
a,
const std::vector<std::string>&
f) {
a +=
f.size(); }
207 void Accumulate(
bool&
a,
const OptionalInt&
f) {
a |=
f.has_value(); }
208 void Accumulate(
bool&
a,
const OptionalString&
f) {
a |=
f.has_value(); }
209 void Accumulate(
bool&
a,
const UDT&
f) {
210 a |=
reinterpret_cast<int64_t>(&
f) & 0x1;
213 #define BM_ManyGetFlag(T) \
214 void BM_ManyGetFlag_##T(benchmark::State& state) { \
215 Accumulator<T>::type res = {}; \
216 while (state.KeepRunningBatch(kNumFlags)) { \
217 for (auto* flag_ptr : FlagPtrs_##T) { \
218 Accumulate(res, absl::GetFlag(*flag_ptr)); \
221 benchmark::DoNotOptimize(res); \
223 BENCHMARK(BM_ManyGetFlag_##T)->ThreadRange(1, 8);
228 char dummy[] =
"dummy";
229 char* argv[] = {
dummy};
235 for (
auto* flag_ptr : FlagPtrs_bool) {
240 BENCHMARK(BM_ThreadedFindCommandLineFlag)->ThreadRange(1, 16);
244 #define InvokeGetFlag(T) \
245 T AbslInvokeGetFlag##T() { return absl::GetFlag(SINGLE_FLAG(T)); } \
246 int odr##T = (benchmark::DoNotOptimize(AbslInvokeGetFlag##T), 1);
UDT & operator=(const UDT &)=default
ABSL_NAMESPACE_BEGIN bool ParseFlag(absl::string_view input, T *dst, std::string *error)
#define BM_ManyGetFlag(T)
std::vector< char * > ParseCommandLine(int argc, char *argv[])
#define COUNT(T, name, index)
CommandLineFlag * FindCommandLineFlag(absl::string_view name)
BENCHMARK_ALWAYS_INLINE void DoNotOptimize(Tp const &value)
std::string UnparseFlag(const T &v)
#define BM_SingleGetFlag(T)
#define T(upbtypeconst, upbtype, ctype, default_value)
#define BENCHMARKED_TYPES(A)
std::string AbslUnparseFlag(const UDT &)
#define BLOAT_FLAG(_unused1, _unused2, index)
constexpr size_t kNumFlags
bool AbslParseFlag(absl::string_view, UDT *, std::string *)
#define REPLICATE(A, T, name)
#define REPLICATE_ALL(A, T, name)
constexpr bool empty() const noexcept
grpc
Author(s):
autogenerated on Fri May 16 2025 02:58:24