protobuf/third_party/benchmark/test/options_test.cc
Go to the documentation of this file.
1 #include "benchmark/benchmark.h"
2 #include <chrono>
3 #include <thread>
4 
5 #if defined(NDEBUG)
6 #undef NDEBUG
7 #endif
8 #include <cassert>
9 
11  while (state.KeepRunning()) {
12  }
13 }
14 
16  std::chrono::milliseconds sleep_duration(state.range(0));
17  while (state.KeepRunning()) {
18  std::this_thread::sleep_for(
19  std::chrono::duration_cast<std::chrono::nanoseconds>(sleep_duration));
20  }
21 }
22 
24 BENCHMARK(BM_basic)->Arg(42);
28 BENCHMARK(BM_basic)->Range(1, 8);
29 BENCHMARK(BM_basic)->RangeMultiplier(2)->Range(1, 8);
30 BENCHMARK(BM_basic)->DenseRange(10, 15);
31 BENCHMARK(BM_basic)->Args({42, 42});
32 BENCHMARK(BM_basic)->Ranges({{64, 512}, {64, 512}});
33 BENCHMARK(BM_basic)->MinTime(0.7);
34 BENCHMARK(BM_basic)->UseRealTime();
35 BENCHMARK(BM_basic)->ThreadRange(2, 4);
36 BENCHMARK(BM_basic)->ThreadPerCpu();
37 BENCHMARK(BM_basic)->Repetitions(3);
38 
40  for (int i = 0; i < 10; ++i) {
41  b->Arg(i);
42  }
43 }
44 
46 
48  // Test that benchmarks specified with an explicit iteration count are
49  // only run once.
50  static bool invoked_before = false;
51  assert(!invoked_before);
52  invoked_before = true;
53 
54  // Test that the requested iteration count is respected.
55  assert(st.max_iterations == 42);
56  size_t actual_iterations = 0;
57  while (st.KeepRunning())
58  ++actual_iterations;
59  assert(st.iterations() == st.max_iterations);
60  assert(st.iterations() == 42);
61 
62 }
63 BENCHMARK(BM_explicit_iteration_count)->Iterations(42);
64 
benchmark::State::max_iterations
const IterationCount max_iterations
Definition: benchmark/include/benchmark/benchmark.h:702
BM_explicit_iteration_count
void BM_explicit_iteration_count(benchmark::State &st)
Definition: protobuf/third_party/benchmark/test/options_test.cc:47
BM_basic
void BM_basic(benchmark::State &state)
Definition: protobuf/third_party/benchmark/test/options_test.cc:10
BENCHMARK
BENCHMARK(BM_basic)
Definition: protobuf/third_party/benchmark/test/options_test.cc:31
benchmark::kMicrosecond
@ kMicrosecond
Definition: benchmark/include/benchmark/benchmark.h:443
benchmark::kMillisecond
@ kMillisecond
Definition: benchmark/include/benchmark/benchmark.h:443
b
uint64_t b
Definition: abseil-cpp/absl/container/internal/layout_test.cc:53
benchmark::internal::Benchmark
Definition: benchmark/include/benchmark/benchmark.h:834
benchmark::kNanosecond
@ kNanosecond
Definition: benchmark/include/benchmark/benchmark.h:443
benchmark::State
Definition: benchmark/include/benchmark/benchmark.h:503
BENCHMARK_MAIN
#define BENCHMARK_MAIN()
Definition: benchmark/include/benchmark/benchmark.h:1338
benchmark::State::iterations
BENCHMARK_ALWAYS_INLINE IterationCount iterations() const
Definition: benchmark/include/benchmark/benchmark.h:683
state
Definition: bloaty/third_party/zlib/contrib/blast/blast.c:41
CustomArgs
void CustomArgs(benchmark::internal::Benchmark *b)
Definition: protobuf/third_party/benchmark/test/options_test.cc:39
benchmark::State::KeepRunning
bool KeepRunning()
Definition: benchmark/include/benchmark/benchmark.h:740
BM_basic_slow
void BM_basic_slow(benchmark::State &state)
Definition: protobuf/third_party/benchmark/test/options_test.cc:15
i
uint64_t i
Definition: abseil-cpp/absl/container/btree_benchmark.cc:230


grpc
Author(s):
autogenerated on Fri May 16 2025 02:59:36