Eric Fiselier | 4d5e91d | 2016-08-29 19:12:01 | [diff] [blame] | 1 | #undef NDEBUG |
Eric Fiselier | 4d5e91d | 2016-08-29 19:12:01 | [diff] [blame] | 2 | #include <cassert> |
Eric Fiselier | fbc9ff2 | 2016-11-05 00:30:27 | [diff] [blame] | 3 | #include <cstddef> |
Eric Fiselier | b08d8b1 | 2016-07-19 23:07:03 | [diff] [blame] | 4 | |
| 5 | #include "benchmark/benchmark.h" |
| 6 | |
| 7 | #if __cplusplus >= 201103L |
| 8 | #error C++11 or greater detected. Should be C++03. |
| 9 | #endif |
| 10 | |
Eric Fiselier | 1903976 | 2018-01-18 04:23:01 | [diff] [blame] | 11 | #ifdef BENCHMARK_HAS_CXX11 |
| 12 | #error C++11 or greater detected by the library. BENCHMARK_HAS_CXX11 is defined. |
| 13 | #endif |
| 14 | |
Eric Fiselier | b08d8b1 | 2016-07-19 23:07:03 | [diff] [blame] | 15 | void BM_empty(benchmark::State& state) { |
Eric Fiselier | fbc9ff2 | 2016-11-05 00:30:27 | [diff] [blame] | 16 | while (state.KeepRunning()) { |
Louis Dionne | 5208ec5 | 2021-07-12 17:15:34 | [diff] [blame] | 17 | volatile benchmark::IterationCount x = state.iterations(); |
Eric Fiselier | fbc9ff2 | 2016-11-05 00:30:27 | [diff] [blame] | 18 | ((void)x); |
| 19 | } |
Eric Fiselier | b08d8b1 | 2016-07-19 23:07:03 | [diff] [blame] | 20 | } |
| 21 | BENCHMARK(BM_empty); |
| 22 | |
Eric Fiselier | 4d5e91d | 2016-08-29 19:12:01 | [diff] [blame] | 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) { |
Eric Fiselier | fbc9ff2 | 2016-11-05 00:30:27 | [diff] [blame] | 26 | assert((state.range(0) == 1 && state.range(1) == 2) || |
| 27 | (state.range(0) == 5 && state.range(1) == 6)); |
| 28 | while (state.KeepRunning()) { |
| 29 | } |
Eric Fiselier | 4d5e91d | 2016-08-29 19:12:01 | [diff] [blame] | 30 | } |
| 31 | BENCHMARK(BM_old_arg_range_interface)->ArgPair(1, 2)->RangePair(5, 5, 6, 6); |
| 32 | |
Eric Fiselier | b08d8b1 | 2016-07-19 23:07:03 | [diff] [blame] | 33 | template <class T, class U> |
| 34 | void BM_template2(benchmark::State& state) { |
Eric Fiselier | fbc9ff2 | 2016-11-05 00:30:27 | [diff] [blame] | 35 | BM_empty(state); |
Eric Fiselier | b08d8b1 | 2016-07-19 23:07:03 | [diff] [blame] | 36 | } |
| 37 | BENCHMARK_TEMPLATE2(BM_template2, int, long); |
| 38 | |
| 39 | template <class T> |
| 40 | void BM_template1(benchmark::State& state) { |
Eric Fiselier | fbc9ff2 | 2016-11-05 00:30:27 | [diff] [blame] | 41 | BM_empty(state); |
Eric Fiselier | b08d8b1 | 2016-07-19 23:07:03 | [diff] [blame] | 42 | } |
| 43 | BENCHMARK_TEMPLATE(BM_template1, long); |
| 44 | BENCHMARK_TEMPLATE1(BM_template1, int); |
| 45 | |
Eric Fiselier | 1903976 | 2018-01-18 04:23:01 | [diff] [blame] | 46 | template <class T> |
Mircea Trofin | a290770 | 2021-12-14 00:02:02 | [diff] [blame] | 47 | struct BM_Fixture : public ::benchmark::Fixture {}; |
Eric Fiselier | 1903976 | 2018-01-18 04:23:01 | [diff] [blame] | 48 | |
| 49 | BENCHMARK_TEMPLATE_F(BM_Fixture, BM_template1, long)(benchmark::State& state) { |
| 50 | BM_empty(state); |
| 51 | } |
| 52 | BENCHMARK_TEMPLATE1_F(BM_Fixture, BM_template2, int)(benchmark::State& state) { |
| 53 | BM_empty(state); |
| 54 | } |
| 55 | |
Eric Fiselier | 133a720 | 2017-04-18 07:17:20 | [diff] [blame] | 56 | void BM_counters(benchmark::State& state) { |
Mircea Trofin | a290770 | 2021-12-14 00:02:02 | [diff] [blame] | 57 | BM_empty(state); |
| 58 | state.counters["Foo"] = 2; |
Eric Fiselier | 133a720 | 2017-04-18 07:17:20 | [diff] [blame] | 59 | } |
| 60 | BENCHMARK(BM_counters); |
| 61 | |
Eric Fiselier | 1903976 | 2018-01-18 04:23:01 | [diff] [blame] | 62 | BENCHMARK_MAIN(); |