2015-03-27 03:37:26 +00:00
|
|
|
#include "benchmark/benchmark_api.h"
|
2016-05-02 17:53:45 +00:00
|
|
|
|
|
|
|
#include <chrono>
|
|
|
|
#include <thread>
|
2015-03-27 03:37:26 +00:00
|
|
|
|
|
|
|
void BM_basic(benchmark::State& state) {
|
|
|
|
while (state.KeepRunning()) {
|
|
|
|
}
|
|
|
|
}
|
2016-03-25 21:47:27 +00:00
|
|
|
|
|
|
|
void BM_basic_slow(benchmark::State& state) {
|
2016-05-11 00:35:36 +00:00
|
|
|
std::chrono::milliseconds sleep_duration(state.range_x());
|
2016-03-25 21:47:27 +00:00
|
|
|
while (state.KeepRunning()) {
|
2016-07-22 21:35:26 +00:00
|
|
|
// Simulate some useful workload by sleeping.
|
|
|
|
// Note: std::this_thread::sleep_for doesn't work with GCC 4.7 on some
|
|
|
|
// platforms.
|
|
|
|
const auto sleep_end = std::chrono::steady_clock::now() + sleep_duration;
|
|
|
|
while (std::chrono::steady_clock::now() < sleep_end) {}
|
2016-03-25 21:47:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-27 03:37:26 +00:00
|
|
|
BENCHMARK(BM_basic);
|
|
|
|
BENCHMARK(BM_basic)->Arg(42);
|
2016-03-25 21:47:27 +00:00
|
|
|
BENCHMARK(BM_basic_slow)->Arg(10)->Unit(benchmark::kNanosecond);
|
|
|
|
BENCHMARK(BM_basic_slow)->Arg(100)->Unit(benchmark::kMicrosecond);
|
|
|
|
BENCHMARK(BM_basic_slow)->Arg(1000)->Unit(benchmark::kMillisecond);
|
2015-03-27 03:37:26 +00:00
|
|
|
BENCHMARK(BM_basic)->Range(1, 8);
|
2016-05-14 13:56:34 +00:00
|
|
|
BENCHMARK(BM_basic)->RangeMultiplier(2)->Range(1, 8);
|
2015-03-27 03:37:26 +00:00
|
|
|
BENCHMARK(BM_basic)->DenseRange(10, 15);
|
|
|
|
BENCHMARK(BM_basic)->ArgPair(42, 42);
|
|
|
|
BENCHMARK(BM_basic)->RangePair(64, 512, 64, 512);
|
|
|
|
BENCHMARK(BM_basic)->MinTime(0.7);
|
|
|
|
BENCHMARK(BM_basic)->UseRealTime();
|
|
|
|
BENCHMARK(BM_basic)->ThreadRange(2, 4);
|
|
|
|
BENCHMARK(BM_basic)->ThreadPerCpu();
|
2016-05-25 03:52:23 +00:00
|
|
|
BENCHMARK(BM_basic)->Repetitions(3);
|
2015-03-27 03:37:26 +00:00
|
|
|
|
2015-09-23 18:44:26 +00:00
|
|
|
void CustomArgs(benchmark::internal::Benchmark* b) {
|
|
|
|
for (int i = 0; i < 10; ++i) {
|
|
|
|
b->Arg(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
BENCHMARK(BM_basic)->Apply(CustomArgs);
|
|
|
|
|
2015-03-27 03:37:26 +00:00
|
|
|
BENCHMARK_MAIN()
|