mirror of
https://github.com/google/benchmark.git
synced 2024-12-27 21:10:19 +08:00
dfe0260754
* Support multiple ranges in the benchmark google-benchmark library allows to provide up to two ranges to the benchmark method (range_x and range_y). However, in many cases it's not sufficient. The patch introduces multi-range features, so user can easily define multiple ranges by passing a vector of integers, and access values through the method range(i). * Remove redundant API Functions State::range_x() and State::range_y() have been removed. They should be replaced by State::range(0) and State::range(1). Functions Benchmark::ArgPair() and Benchmark::RangePair() have been removed. They should be replaced by Benchmark::Args() and Benchmark::Ranges().
45 lines
1.2 KiB
C++
45 lines
1.2 KiB
C++
#include "benchmark/benchmark_api.h"
|
|
|
|
#include <chrono>
|
|
#include <thread>
|
|
|
|
void BM_basic(benchmark::State& state) {
|
|
while (state.KeepRunning()) {
|
|
}
|
|
}
|
|
|
|
void BM_basic_slow(benchmark::State& state) {
|
|
std::chrono::milliseconds sleep_duration(state.range(0));
|
|
while (state.KeepRunning()) {
|
|
std::this_thread::sleep_for(
|
|
std::chrono::duration_cast<std::chrono::nanoseconds>(sleep_duration)
|
|
);
|
|
}
|
|
}
|
|
|
|
BENCHMARK(BM_basic);
|
|
BENCHMARK(BM_basic)->Arg(42);
|
|
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);
|
|
BENCHMARK(BM_basic)->Range(1, 8);
|
|
BENCHMARK(BM_basic)->RangeMultiplier(2)->Range(1, 8);
|
|
BENCHMARK(BM_basic)->DenseRange(10, 15);
|
|
BENCHMARK(BM_basic)->Args({42, 42});
|
|
BENCHMARK(BM_basic)->Ranges({{64, 512}, {64, 512}});
|
|
BENCHMARK(BM_basic)->MinTime(0.7);
|
|
BENCHMARK(BM_basic)->UseRealTime();
|
|
BENCHMARK(BM_basic)->ThreadRange(2, 4);
|
|
BENCHMARK(BM_basic)->ThreadPerCpu();
|
|
BENCHMARK(BM_basic)->Repetitions(3);
|
|
|
|
void CustomArgs(benchmark::internal::Benchmark* b) {
|
|
for (int i = 0; i < 10; ++i) {
|
|
b->Arg(i);
|
|
}
|
|
}
|
|
|
|
BENCHMARK(BM_basic)->Apply(CustomArgs);
|
|
|
|
BENCHMARK_MAIN()
|