added option to change range multiplier

This commit is contained in:
Ismael 2016-05-14 15:56:34 +02:00
parent 360e66c1c4
commit c60eefdbb7
3 changed files with 24 additions and 5 deletions

View File

@ -444,6 +444,10 @@ public:
// Threads, etc.
Benchmark* Apply(void (*func)(Benchmark* benchmark));
// Set the range multiplier for non-dense range. If not called, the range multiplier
// kRangeMultiplier will be used.
Benchmark* RangeMultiplier(int multiplier);
// Set the minimum amount of time to use when running this benchmark. This
// option overrides the `benchmark_min_time` flag.
Benchmark* MinTime(double t);

View File

@ -287,6 +287,7 @@ struct Benchmark::Instance {
bool has_arg2;
int arg2;
TimeUnit time_unit;
int range_multiplier;
bool use_real_time;
bool use_manual_time;
double min_time;
@ -326,6 +327,7 @@ public:
void DenseRange(int start, int limit);
void ArgPair(int start, int limit);
void RangePair(int lo1, int hi1, int lo2, int hi2);
void RangeMultiplier(int multiplier);
void MinTime(double n);
void UseRealTime();
void UseManualTime();
@ -343,6 +345,7 @@ private:
int arg_count_;
std::vector< std::pair<int, int> > args_; // Args for all benchmark runs
TimeUnit time_unit_;
int range_multiplier_;
double min_time_;
bool use_real_time_;
bool use_manual_time_;
@ -404,6 +407,7 @@ bool BenchmarkFamilies::FindBenchmarks(
instance.has_arg2 = family->arg_count_ == 2;
instance.arg2 = args.second;
instance.time_unit = family->time_unit_;
instance.range_multiplier = family->range_multiplier_;
instance.min_time = family->min_time_;
instance.use_real_time = family->use_real_time_;
instance.use_manual_time = family->use_manual_time_;
@ -442,8 +446,8 @@ bool BenchmarkFamilies::FindBenchmarks(
BenchmarkImp::BenchmarkImp(const char* name)
: name_(name), arg_count_(-1), time_unit_(kNanosecond),
min_time_(0.0), use_real_time_(false),
use_manual_time_(false) {
range_multiplier_(kRangeMultiplier), min_time_(0.0),
use_real_time_(false), use_manual_time_(false) {
}
BenchmarkImp::~BenchmarkImp() {
@ -463,7 +467,7 @@ void BenchmarkImp::Range(int start, int limit) {
CHECK(arg_count_ == -1 || arg_count_ == 1);
arg_count_ = 1;
std::vector<int> arglist;
AddRange(&arglist, start, limit, kRangeMultiplier);
AddRange(&arglist, start, limit, range_multiplier_);
for (int i : arglist) {
args_.emplace_back(i, -1);
@ -490,8 +494,8 @@ void BenchmarkImp::RangePair(int lo1, int hi1, int lo2, int hi2) {
CHECK(arg_count_ == -1 || arg_count_ == 2);
arg_count_ = 2;
std::vector<int> arglist1, arglist2;
AddRange(&arglist1, lo1, hi1, kRangeMultiplier);
AddRange(&arglist2, lo2, hi2, kRangeMultiplier);
AddRange(&arglist1, lo1, hi1, range_multiplier_);
AddRange(&arglist2, lo2, hi2, range_multiplier_);
for (int i : arglist1) {
for (int j : arglist2) {
@ -500,6 +504,11 @@ void BenchmarkImp::RangePair(int lo1, int hi1, int lo2, int hi2) {
}
}
void BenchmarkImp::RangeMultiplier(int multiplier) {
CHECK_GE(multiplier, 2);
range_multiplier_ = multiplier;
}
void BenchmarkImp::MinTime(double t) {
CHECK(t > 0.0);
min_time_ = t;
@ -607,6 +616,11 @@ Benchmark* Benchmark::Apply(void (*custom_arguments)(Benchmark* benchmark)) {
return this;
}
Benchmark* Benchmark::RangeMultiplier(int multiplier) {
imp_->RangeMultiplier(multiplier);
return this;
}
Benchmark* Benchmark::MinTime(double t) {
imp_->MinTime(t);
return this;

View File

@ -23,6 +23,7 @@ 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)->ArgPair(42, 42);
BENCHMARK(BM_basic)->RangePair(64, 512, 64, 512);