You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
1.6 KiB

  1. #undef NDEBUG
  2. #include <cassert>
  3. #include <cstddef>
  4. #include "benchmark/benchmark.h"
  5. #if __cplusplus >= 201103L
  6. #error C++11 or greater detected. Should be C++03.
  7. #endif
  8. #ifdef BENCHMARK_HAS_CXX11
  9. #error C++11 or greater detected by the library. BENCHMARK_HAS_CXX11 is defined.
  10. #endif
  11. void BM_empty(benchmark::State& state) {
  12. while (state.KeepRunning()) {
  13. volatile benchmark::IterationCount x = state.iterations();
  14. ((void)x);
  15. }
  16. }
  17. BENCHMARK(BM_empty);
  18. // The new C++11 interface for args/ranges requires initializer list support.
  19. // Therefore we provide the old interface to support C++03.
  20. void BM_old_arg_range_interface(benchmark::State& state) {
  21. assert((state.range(0) == 1 && state.range(1) == 2) ||
  22. (state.range(0) == 5 && state.range(1) == 6));
  23. while (state.KeepRunning()) {
  24. }
  25. }
  26. BENCHMARK(BM_old_arg_range_interface)->ArgPair(1, 2)->RangePair(5, 5, 6, 6);
  27. template <class T, class U>
  28. void BM_template2(benchmark::State& state) {
  29. BM_empty(state);
  30. }
  31. BENCHMARK_TEMPLATE2(BM_template2, int, long);
  32. template <class T>
  33. void BM_template1(benchmark::State& state) {
  34. BM_empty(state);
  35. }
  36. BENCHMARK_TEMPLATE(BM_template1, long);
  37. BENCHMARK_TEMPLATE1(BM_template1, int);
  38. template <class T>
  39. struct BM_Fixture : public ::benchmark::Fixture {
  40. };
  41. BENCHMARK_TEMPLATE_F(BM_Fixture, BM_template1, long)(benchmark::State& state) {
  42. BM_empty(state);
  43. }
  44. BENCHMARK_TEMPLATE1_F(BM_Fixture, BM_template2, int)(benchmark::State& state) {
  45. BM_empty(state);
  46. }
  47. void BM_counters(benchmark::State& state) {
  48. BM_empty(state);
  49. state.counters["Foo"] = 2;
  50. }
  51. BENCHMARK(BM_counters);
  52. BENCHMARK_MAIN();