brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.6 KiB · 9711c1b Raw
63 lines · plain
1#undef NDEBUG2#include <cassert>3#include <cstddef>4 5#include "benchmark/benchmark.h"6 7#if __cplusplus >= 201103L8#error C++11 or greater detected. Should be C++03.9#endif10 11#ifdef BENCHMARK_HAS_CXX1112#error C++11 or greater detected by the library. BENCHMARK_HAS_CXX11 is defined.13#endif14 15void BM_empty(benchmark::State& state) {16  while (state.KeepRunning()) {17    volatile benchmark::IterationCount x = state.iterations();18    ((void)x);19  }20}21BENCHMARK(BM_empty);22 23// 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) {26  assert((state.range(0) == 1 && state.range(1) == 2) ||27         (state.range(0) == 5 && state.range(1) == 6));28  while (state.KeepRunning()) {29  }30}31BENCHMARK(BM_old_arg_range_interface)->ArgPair(1, 2)->RangePair(5, 5, 6, 6);32 33template <class T, class U>34void BM_template2(benchmark::State& state) {35  BM_empty(state);36}37BENCHMARK_TEMPLATE2(BM_template2, int, long);38 39template <class T>40void BM_template1(benchmark::State& state) {41  BM_empty(state);42}43BENCHMARK_TEMPLATE(BM_template1, long);44BENCHMARK_TEMPLATE1(BM_template1, int);45 46template <class T>47struct BM_Fixture : public ::benchmark::Fixture {};48 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 56void BM_counters(benchmark::State& state) {57  BM_empty(state);58  state.counters["Foo"] = 2;59}60BENCHMARK(BM_counters);61 62BENCHMARK_MAIN();63