added SetComplexityN
diff --git a/include/benchmark/benchmark_api.h b/include/benchmark/benchmark_api.h
index b3ebb27..5f1ee20 100644
--- a/include/benchmark/benchmark_api.h
+++ b/include/benchmark/benchmark_api.h
@@ -312,6 +312,19 @@
return bytes_processed_;
}
+ // If this routine is called with complexity_n > 0 and complexity report is requested for the
+ // family benchmark, then current benchmark will be part of the computation and complexity_n will
+ // represent the length of N.
+ BENCHMARK_ALWAYS_INLINE
+ void SetComplexityN(size_t complexity_n) {
+ complexity_n_ = complexity_n;
+ }
+
+ BENCHMARK_ALWAYS_INLINE
+ size_t complexity_n() {
+ return complexity_n_;
+ }
+
// If this routine is called with items > 0, then an items/s
// label is printed on the benchmark report line for the currently
// executing benchmark. It is typically called at the end of a processing
@@ -383,6 +396,8 @@
size_t bytes_processed_;
size_t items_processed_;
+ size_t complexity_n_;
+
public:
// Index of the executing thread. Values from [0, threads).
const int thread_index;
@@ -466,7 +481,7 @@
// to control how many iterations are run, and in the printing of items/second
// or MB/second values.
Benchmark* UseManualTime();
-
+
// Set the asymptotic computational complexity for the benchmark. If called
// the asymptotic computational complexity will be shown on the output.
Benchmark* Complexity(BigO complexity);
diff --git a/include/benchmark/reporter.h b/include/benchmark/reporter.h
index 2e164db..8656402 100644
--- a/include/benchmark/reporter.h
+++ b/include/benchmark/reporter.h
@@ -50,8 +50,7 @@
items_per_second(0),
max_heapbytes_used(0),
complexity(oNone),
- arg1(0),
- arg2(0),
+ complexity_n(0),
report_big_o(false),
report_rms(false) {}
@@ -71,8 +70,7 @@
// Keep track of arguments to compute asymptotic complexity
BigO complexity;
- int arg1;
- int arg2;
+ int complexity_n;
// Inform print function whether the current run is a complexity report
bool report_big_o;
diff --git a/src/benchmark.cc b/src/benchmark.cc
index 2245389..03f524b 100644
--- a/src/benchmark.cc
+++ b/src/benchmark.cc
@@ -116,9 +116,10 @@
//static benchmark::MallocCounter *benchmark_mc;
struct ThreadStats {
- ThreadStats() : bytes_processed(0), items_processed(0) {}
+ ThreadStats() : bytes_processed(0), items_processed(0), complexity_n(0) {}
int64_t bytes_processed;
int64_t items_processed;
+ size_t complexity_n;
};
// Timer management class
@@ -693,6 +694,7 @@
MutexLock l(GetBenchmarkLock());
total->bytes_processed += st.bytes_processed();
total->items_processed += st.items_processed();
+ total->complexity_n += st.complexity_n();
}
timer_manager->Finalize();
@@ -798,8 +800,7 @@
report.cpu_accumulated_time = cpu_accumulated_time;
report.bytes_per_second = bytes_per_second;
report.items_per_second = items_per_second;
- report.arg1 = b.arg1;
- report.arg2 = b.arg2;
+ report.complexity_n = total.complexity_n;
report.complexity = b.complexity;
reports.push_back(report);
@@ -851,7 +852,8 @@
bytes_processed_(0), items_processed_(0),
thread_index(thread_i),
threads(n_threads),
- max_iterations(max_iters)
+ max_iterations(max_iters),
+ complexity_n_(0)
{
CHECK(max_iterations != 0) << "At least one iteration must be run";
CHECK_LT(thread_index, threads) << "thread_index must be less than threads";
diff --git a/src/reporter.cc b/src/reporter.cc
index f928d69..544df87 100644
--- a/src/reporter.cc
+++ b/src/reporter.cc
@@ -90,7 +90,7 @@
// Populate the accumulators.
for (const Run& run : reports) {
- n.push_back(run.arg1);
+ n.push_back(run.complexity_n);
real_time.push_back(run.real_accumulated_time/run.iterations);
cpu_time.push_back(run.cpu_accumulated_time/run.iterations);
}
diff --git a/test/complexity_test.cc b/test/complexity_test.cc
index e169ad9..e454ee4 100644
--- a/test/complexity_test.cc
+++ b/test/complexity_test.cc
@@ -26,6 +26,7 @@
void BM_Complexity_O1(benchmark::State& state) {
while (state.KeepRunning()) {
}
+ state.SetComplexityN(state.range_x());
}
BENCHMARK(BM_Complexity_O1) -> Range(1, 1<<18) -> Complexity(benchmark::o1);
@@ -35,6 +36,7 @@
while (state.KeepRunning()) {
benchmark::DoNotOptimize(std::find(v.begin(), v.end(), item_not_in_vector));
}
+ state.SetComplexityN(state.range_x());
}
BENCHMARK(BM_Complexity_O_N) -> RangeMultiplier(2) -> Range(1<<10, 1<<16) -> Complexity(benchmark::oN);
BENCHMARK(BM_Complexity_O_N) -> RangeMultiplier(2) -> Range(1<<10, 1<<16) -> Complexity(benchmark::oAuto);
@@ -42,6 +44,7 @@
static void BM_Complexity_O_N_Squared(benchmark::State& state) {
std::string s1(state.range_x(), '-');
std::string s2(state.range_x(), '-');
+ state.SetComplexityN(state.range_x());
while (state.KeepRunning())
for(char& c1 : s1) {
for(char& c2 : s2) {
@@ -56,6 +59,7 @@
std::string s1(state.range_x(), '-');
std::string s2(state.range_x(), '-');
std::string s3(state.range_x(), '-');
+ state.SetComplexityN(state.range_x());
while (state.KeepRunning())
for(char& c1 : s1) {
for(char& c2 : s2) {
@@ -75,6 +79,7 @@
while (state.KeepRunning()) {
benchmark::DoNotOptimize(m.find(item_not_in_vector));
}
+ state.SetComplexityN(state.range_x());
}
BENCHMARK(BM_Complexity_O_log_N)
-> RangeMultiplier(2) -> Range(1<<10, 1<<16) -> Complexity(benchmark::oLogN);
@@ -84,6 +89,7 @@
while (state.KeepRunning()) {
std::sort(v.begin(), v.end());
}
+ state.SetComplexityN(state.range_x());
}
BENCHMARK(BM_Complexity_O_N_log_N) -> RangeMultiplier(2) -> Range(1<<10, 1<<16) -> Complexity(benchmark::oNLogN);
BENCHMARK(BM_Complexity_O_N_log_N) -> RangeMultiplier(2) -> Range(1<<10, 1<<16) -> Complexity(benchmark::oAuto);