diff --git a/AUTHORS b/AUTHORS index c4b059df..49f500f1 100644 --- a/AUTHORS +++ b/AUTHORS @@ -32,6 +32,7 @@ Oleksandr Sochka Paul Redmond Radoslav Yovchev Shuo Chen +Yixuan Qiu Yusuke Suzuki Dirac Research Zbigniew Skowron diff --git a/CONTRIBUTORS b/CONTRIBUTORS index 8ca4565a..c0c0292e 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -50,6 +50,7 @@ Pierre Phaneuf Radoslav Yovchev Ray Glover Shuo Chen +Yixuan Qiu Yusuke Suzuki Tobias Ulvgård Zbigniew Skowron diff --git a/src/complexity.cc b/src/complexity.cc index a4c57c43..24b3ed4f 100644 --- a/src/complexity.cc +++ b/src/complexity.cc @@ -194,16 +194,16 @@ std::vector ComputeStats( CHECK_EQ(run_iterations, run.iterations); if (run.error_occurred) continue; real_accumulated_time_stat += - Stat1_d(run.real_accumulated_time / run.iterations, run.iterations); + Stat1_d(run.real_accumulated_time / run.iterations); cpu_accumulated_time_stat += - Stat1_d(run.cpu_accumulated_time / run.iterations, run.iterations); - items_per_second_stat += Stat1_d(run.items_per_second, run.iterations); - bytes_per_second_stat += Stat1_d(run.bytes_per_second, run.iterations); + Stat1_d(run.cpu_accumulated_time / run.iterations); + items_per_second_stat += Stat1_d(run.items_per_second); + bytes_per_second_stat += Stat1_d(run.bytes_per_second); // user counters for(auto const& cnt : run.counters) { auto it = counter_stats.find(cnt.first); CHECK_NE(it, counter_stats.end()); - it->second.s += Stat1_d(cnt.second, run.iterations); + it->second.s += Stat1_d(cnt.second); } } diff --git a/src/stat.h b/src/stat.h index 136c3aa8..d356875b 100644 --- a/src/stat.h +++ b/src/stat.h @@ -119,18 +119,22 @@ class Stat1 { if (numsamples_ == 0) return VType(); VType mean = sum_ * (1.0 / numsamples_); if (stddev) { - VType avg_squares = sum_squares_ * (1.0 / numsamples_); - *stddev = Sqrt(avg_squares - Sqr(mean)); + // Sample standard deviation is undefined for n = 1 + if (numsamples_ == 1) { + *stddev = VType(); + } else { + VType avg_squares = sum_squares_ * (1.0 / numsamples_); + *stddev = Sqrt(numsamples_ / (numsamples_ - 1.0) * (avg_squares - Sqr(mean))); + } } return mean; } // Return the standard deviation of the sample set VType StdDev() const { - if (numsamples_ == 0) return VType(); - VType mean = Mean(); - VType avg_squares = sum_squares_ * (1.0 / numsamples_); - return Sqrt(avg_squares - Sqr(mean)); + VType stddev = VType(); + Mean(&stddev); + return stddev; } private: