[Workflow] Try to fix code-formatter failing to find changes in some cases.
[llvm-project.git] / third-party / benchmark / test / cxx03_test.cc
blob9711c1bd4a9b3420ad1a96f04d8fc4f2a5073b4b
1 #undef NDEBUG
2 #include <cassert>
3 #include <cstddef>
5 #include "benchmark/benchmark.h"
7 #if __cplusplus >= 201103L
8 #error C++11 or greater detected. Should be C++03.
9 #endif
11 #ifdef BENCHMARK_HAS_CXX11
12 #error C++11 or greater detected by the library. BENCHMARK_HAS_CXX11 is defined.
13 #endif
15 void BM_empty(benchmark::State& state) {
16 while (state.KeepRunning()) {
17 volatile benchmark::IterationCount x = state.iterations();
18 ((void)x);
21 BENCHMARK(BM_empty);
23 // The new C++11 interface for args/ranges requires initializer list support.
24 // Therefore we provide the old interface to support C++03.
25 void BM_old_arg_range_interface(benchmark::State& state) {
26 assert((state.range(0) == 1 && state.range(1) == 2) ||
27 (state.range(0) == 5 && state.range(1) == 6));
28 while (state.KeepRunning()) {
31 BENCHMARK(BM_old_arg_range_interface)->ArgPair(1, 2)->RangePair(5, 5, 6, 6);
33 template <class T, class U>
34 void BM_template2(benchmark::State& state) {
35 BM_empty(state);
37 BENCHMARK_TEMPLATE2(BM_template2, int, long);
39 template <class T>
40 void BM_template1(benchmark::State& state) {
41 BM_empty(state);
43 BENCHMARK_TEMPLATE(BM_template1, long);
44 BENCHMARK_TEMPLATE1(BM_template1, int);
46 template <class T>
47 struct BM_Fixture : public ::benchmark::Fixture {};
49 BENCHMARK_TEMPLATE_F(BM_Fixture, BM_template1, long)(benchmark::State& state) {
50 BM_empty(state);
52 BENCHMARK_TEMPLATE1_F(BM_Fixture, BM_template2, int)(benchmark::State& state) {
53 BM_empty(state);
56 void BM_counters(benchmark::State& state) {
57 BM_empty(state);
58 state.counters["Foo"] = 2;
60 BENCHMARK(BM_counters);
62 BENCHMARK_MAIN();