Home | History | Annotate | Download | only in test
      1 #include "benchmark/benchmark_api.h"
      2 
      3 #include <chrono>
      4 #include <thread>
      5 
      6 void BM_basic(benchmark::State& state) {
      7   while (state.KeepRunning()) {
      8   }
      9 }
     10 
     11 void BM_basic_slow(benchmark::State& state) {
     12   std::chrono::milliseconds sleep_duration(state.range(0));
     13   while (state.KeepRunning()) {
     14     std::this_thread::sleep_for(
     15         std::chrono::duration_cast<std::chrono::nanoseconds>(sleep_duration));
     16   }
     17 }
     18 
     19 BENCHMARK(BM_basic);
     20 BENCHMARK(BM_basic)->Arg(42);
     21 BENCHMARK(BM_basic_slow)->Arg(10)->Unit(benchmark::kNanosecond);
     22 BENCHMARK(BM_basic_slow)->Arg(100)->Unit(benchmark::kMicrosecond);
     23 BENCHMARK(BM_basic_slow)->Arg(1000)->Unit(benchmark::kMillisecond);
     24 BENCHMARK(BM_basic)->Range(1, 8);
     25 BENCHMARK(BM_basic)->RangeMultiplier(2)->Range(1, 8);
     26 BENCHMARK(BM_basic)->DenseRange(10, 15);
     27 BENCHMARK(BM_basic)->Args({42, 42});
     28 BENCHMARK(BM_basic)->Ranges({{64, 512}, {64, 512}});
     29 BENCHMARK(BM_basic)->MinTime(0.7);
     30 BENCHMARK(BM_basic)->UseRealTime();
     31 BENCHMARK(BM_basic)->ThreadRange(2, 4);
     32 BENCHMARK(BM_basic)->ThreadPerCpu();
     33 BENCHMARK(BM_basic)->Repetitions(3);
     34 
     35 void CustomArgs(benchmark::internal::Benchmark* b) {
     36   for (int i = 0; i < 10; ++i) {
     37     b->Arg(i);
     38   }
     39 }
     40 
     41 BENCHMARK(BM_basic)->Apply(CustomArgs);
     42 
     43 BENCHMARK_MAIN()
     44