blob: 9711c1bd4a9b3420ad1a96f04d8fc4f2a5073b4b [file] [log] [blame]
Eric Fiselier4d5e91d2016-08-29 19:12:011#undef NDEBUG
Eric Fiselier4d5e91d2016-08-29 19:12:012#include <cassert>
Eric Fiselierfbc9ff22016-11-05 00:30:273#include <cstddef>
Eric Fiselierb08d8b12016-07-19 23:07:034
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 Fiselier19039762018-01-18 04:23:0111#ifdef BENCHMARK_HAS_CXX11
12#error C++11 or greater detected by the library. BENCHMARK_HAS_CXX11 is defined.
13#endif
14
Eric Fiselierb08d8b12016-07-19 23:07:0315void BM_empty(benchmark::State& state) {
Eric Fiselierfbc9ff22016-11-05 00:30:2716 while (state.KeepRunning()) {
Louis Dionne5208ec52021-07-12 17:15:3417 volatile benchmark::IterationCount x = state.iterations();
Eric Fiselierfbc9ff22016-11-05 00:30:2718 ((void)x);
19 }
Eric Fiselierb08d8b12016-07-19 23:07:0320}
21BENCHMARK(BM_empty);
22
Eric Fiselier4d5e91d2016-08-29 19:12:0123// The new C++11 interface for args/ranges requires initializer list support.
24// Therefore we provide the old interface to support C++03.
25void BM_old_arg_range_interface(benchmark::State& state) {
Eric Fiselierfbc9ff22016-11-05 00:30:2726 assert((state.range(0) == 1 && state.range(1) == 2) ||
27 (state.range(0) == 5 && state.range(1) == 6));
28 while (state.KeepRunning()) {
29 }
Eric Fiselier4d5e91d2016-08-29 19:12:0130}
31BENCHMARK(BM_old_arg_range_interface)->ArgPair(1, 2)->RangePair(5, 5, 6, 6);
32
Eric Fiselierb08d8b12016-07-19 23:07:0333template <class T, class U>
34void BM_template2(benchmark::State& state) {
Eric Fiselierfbc9ff22016-11-05 00:30:2735 BM_empty(state);
Eric Fiselierb08d8b12016-07-19 23:07:0336}
37BENCHMARK_TEMPLATE2(BM_template2, int, long);
38
39template <class T>
40void BM_template1(benchmark::State& state) {
Eric Fiselierfbc9ff22016-11-05 00:30:2741 BM_empty(state);
Eric Fiselierb08d8b12016-07-19 23:07:0342}
43BENCHMARK_TEMPLATE(BM_template1, long);
44BENCHMARK_TEMPLATE1(BM_template1, int);
45
Eric Fiselier19039762018-01-18 04:23:0146template <class T>
Mircea Trofina2907702021-12-14 00:02:0247struct BM_Fixture : public ::benchmark::Fixture {};
Eric Fiselier19039762018-01-18 04:23:0148
49BENCHMARK_TEMPLATE_F(BM_Fixture, BM_template1, long)(benchmark::State& state) {
50 BM_empty(state);
51}
52BENCHMARK_TEMPLATE1_F(BM_Fixture, BM_template2, int)(benchmark::State& state) {
53 BM_empty(state);
54}
55
Eric Fiselier133a7202017-04-18 07:17:2056void BM_counters(benchmark::State& state) {
Mircea Trofina2907702021-12-14 00:02:0257 BM_empty(state);
58 state.counters["Foo"] = 2;
Eric Fiselier133a7202017-04-18 07:17:2059}
60BENCHMARK(BM_counters);
61
Eric Fiselier19039762018-01-18 04:23:0162BENCHMARK_MAIN();