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