blob: baa9ed9262baa0e911a3c98b844552453f2bc1a0 [file] [log] [blame]
Eric Fiselier4d5e91d2016-08-29 19:12:01 +00001#undef NDEBUG
Eric Fiselier4d5e91d2016-08-29 19:12:01 +00002#include <cassert>
Eric Fiselierfbc9ff22016-11-05 00:30:27 +00003#include <cstddef>
Eric Fiselierb08d8b12016-07-19 23:07:03 +00004
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:01 +000011#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:03 +000015void BM_empty(benchmark::State& state) {
Eric Fiselierfbc9ff22016-11-05 00:30:27 +000016 while (state.KeepRunning()) {
17 volatile std::size_t x = state.iterations();
18 ((void)x);
19 }
Eric Fiselierb08d8b12016-07-19 23:07:03 +000020}
21BENCHMARK(BM_empty);
22
Eric Fiselier4d5e91d2016-08-29 19:12:01 +000023// 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:27 +000026 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:01 +000030}
31BENCHMARK(BM_old_arg_range_interface)->ArgPair(1, 2)->RangePair(5, 5, 6, 6);
32
Eric Fiselierb08d8b12016-07-19 23:07:03 +000033template <class T, class U>
34void BM_template2(benchmark::State& state) {
Eric Fiselierfbc9ff22016-11-05 00:30:27 +000035 BM_empty(state);
Eric Fiselierb08d8b12016-07-19 23:07:03 +000036}
37BENCHMARK_TEMPLATE2(BM_template2, int, long);
38
39template <class T>
40void BM_template1(benchmark::State& state) {
Eric Fiselierfbc9ff22016-11-05 00:30:27 +000041 BM_empty(state);
Eric Fiselierb08d8b12016-07-19 23:07:03 +000042}
43BENCHMARK_TEMPLATE(BM_template1, long);
44BENCHMARK_TEMPLATE1(BM_template1, int);
45
Eric Fiselier19039762018-01-18 04:23:01 +000046template <class T>
47struct BM_Fixture : public ::benchmark::Fixture {
48};
49
50BENCHMARK_TEMPLATE_F(BM_Fixture, BM_template1, long)(benchmark::State& state) {
51 BM_empty(state);
52}
53BENCHMARK_TEMPLATE1_F(BM_Fixture, BM_template2, int)(benchmark::State& state) {
54 BM_empty(state);
55}
56
Eric Fiselier133a7202017-04-18 07:17:20 +000057void BM_counters(benchmark::State& state) {
58 BM_empty(state);
59 state.counters["Foo"] = 2;
60}
61BENCHMARK(BM_counters);
62
Eric Fiselier19039762018-01-18 04:23:01 +000063BENCHMARK_MAIN();