add support for step in DenseRange() (#260)
diff --git a/include/benchmark/benchmark_api.h b/include/benchmark/benchmark_api.h
index b4aa21c..c2e8edc 100644
--- a/include/benchmark/benchmark_api.h
+++ b/include/benchmark/benchmark_api.h
@@ -489,9 +489,9 @@
// REQUIRES: The function passed to the constructor must accept an arg1.
Benchmark* Range(int start, int limit);
- // Run this benchmark once for every value in the range [start..limit]
+ // Run this benchmark once for all values in the range [start..limit] with specific step
// REQUIRES: The function passed to the constructor must accept an arg1.
- Benchmark* DenseRange(int start, int limit);
+ Benchmark* DenseRange(int start, int limit, int step = 1);
// Run this benchmark once with "x,y" as the extra arguments passed
// to the function.
diff --git a/src/benchmark.cc b/src/benchmark.cc
index cb8e132..aece72f 100644
--- a/src/benchmark.cc
+++ b/src/benchmark.cc
@@ -354,7 +354,7 @@
void Arg(int x);
void Unit(TimeUnit unit);
void Range(int start, int limit);
- void DenseRange(int start, int limit);
+ void DenseRange(int start, int limit, int step = 1);
void ArgPair(int start, int limit);
void RangePair(int lo1, int hi1, int lo2, int hi2);
void RangeMultiplier(int multiplier);
@@ -518,12 +518,12 @@
}
}
-void BenchmarkImp::DenseRange(int start, int limit) {
+void BenchmarkImp::DenseRange(int start, int limit, int step) {
CHECK(arg_count_ == -1 || arg_count_ == 1);
arg_count_ = 1;
CHECK_GE(start, 0);
CHECK_LE(start, limit);
- for (int arg = start; arg <= limit; arg++) {
+ for (int arg = start; arg <= limit; arg += step) {
args_.emplace_back(arg, -1);
}
}
@@ -655,8 +655,8 @@
return this;
}
-Benchmark* Benchmark::DenseRange(int start, int limit) {
- imp_->DenseRange(start, limit);
+Benchmark* Benchmark::DenseRange(int start, int limit, int step) {
+ imp_->DenseRange(start, limit, step);
return this;
}