diff options
Diffstat (limited to 'tools/speed_stats.cc')
-rw-r--r-- | tools/speed_stats.cc | 53 |
1 files changed, 32 insertions, 21 deletions
diff --git a/tools/speed_stats.cc b/tools/speed_stats.cc index 2aea8a0..cdef814 100644 --- a/tools/speed_stats.cc +++ b/tools/speed_stats.cc @@ -5,6 +5,7 @@ #include "tools/speed_stats.h" +#include <inttypes.h> #include <math.h> #include <stddef.h> #include <stdio.h> @@ -12,18 +13,17 @@ #include <algorithm> #include <string> -#include "lib/jxl/base/robust_statistics.h" - namespace jpegxl { namespace tools { void SpeedStats::NotifyElapsed(double elapsed_seconds) { - JXL_ASSERT(elapsed_seconds > 0.0); - elapsed_.push_back(elapsed_seconds); + if (elapsed_seconds > 0.0) { + elapsed_.push_back(elapsed_seconds); + } } -jxl::Status SpeedStats::GetSummary(SpeedStats::Summary* s) { - if (elapsed_.empty()) return JXL_FAILURE("Didn't call NotifyElapsed"); +bool SpeedStats::GetSummary(SpeedStats::Summary* s) { + if (elapsed_.empty()) return false; s->min = *std::min_element(elapsed_.begin(), elapsed_.end()); s->max = *std::max_element(elapsed_.begin(), elapsed_.end()); @@ -45,23 +45,30 @@ jxl::Status SpeedStats::GetSummary(SpeedStats::Summary* s) { } // Prefer geomean unless numerically unreliable (too many reps) - if (std::pow(elapsed_[0], elapsed_.size()) < 1E100) { + if (pow(elapsed_[0], elapsed_.size()) < 1E100) { double product = 1.0; for (size_t i = 1; i < elapsed_.size(); ++i) { product *= elapsed_[i]; } - s->central_tendency = std::pow(product, 1.0 / (elapsed_.size() - 1)); + s->central_tendency = pow(product, 1.0 / (elapsed_.size() - 1)); s->variability = 0.0; s->type = " geomean:"; return true; } - // Else: mode + // Else: median std::sort(elapsed_.begin(), elapsed_.end()); - s->central_tendency = jxl::HalfSampleMode()(elapsed_.data(), elapsed_.size()); - s->variability = jxl::MedianAbsoluteDeviation(elapsed_, s->central_tendency); - s->type = "mode: "; + s->central_tendency = elapsed_.data()[elapsed_.size() / 2]; + std::vector<double> deviations(elapsed_.size()); + for (size_t i = 0; i < elapsed_.size(); i++) { + deviations[i] = fabs(elapsed_[i] - s->central_tendency); + } + std::nth_element(deviations.begin(), + deviations.begin() + deviations.size() / 2, + deviations.end()); + s->variability = deviations[deviations.size() / 2]; + s->type = "median: "; return true; } @@ -77,18 +84,18 @@ std::string SummaryStat(double value, const char* unit, const double value_min = value / s.max; const double value_max = value / s.min; - int ret = snprintf(stat_str, sizeof(stat_str), ",%s %.2f %s/s [%.2f, %.2f]", - s.type, value_tendency, unit, value_min, value_max); - (void)ret; // ret is unused when JXL_ASSERT is disabled. - JXL_ASSERT(ret < static_cast<int>(sizeof(stat_str))); + snprintf(stat_str, sizeof(stat_str), ",%s %.2f %s/s [%.2f, %.2f]", s.type, + value_tendency, unit, value_min, value_max); return stat_str; } } // namespace -jxl::Status SpeedStats::Print(size_t worker_threads) { +bool SpeedStats::Print(size_t worker_threads) { Summary s; - JXL_RETURN_IF_ERROR(GetSummary(&s)); + if (!GetSummary(&s)) { + return false; + } std::string mps_stats = SummaryStat(xsize_ * ysize_ * 1e-6, "MP", s); std::string mbs_stats = SummaryStat(file_size_ * 1e-6, "MB", s); @@ -97,9 +104,13 @@ jxl::Status SpeedStats::Print(size_t worker_threads) { snprintf(variability, sizeof(variability), " (var %.2f)", s.variability); } - fprintf(stderr, "%zu x %zu%s%s%s, %zu reps, %zu threads.\n", xsize_, ysize_, - mps_stats.c_str(), mbs_stats.c_str(), variability, elapsed_.size(), - worker_threads); + fprintf(stderr, + "%" PRIu64 " x %" PRIu64 "%s%s%s, %" PRIu64 " reps, %" PRIu64 + " threads.\n", + static_cast<uint64_t>(xsize_), static_cast<uint64_t>(ysize_), + mps_stats.c_str(), mbs_stats.c_str(), variability, + static_cast<uint64_t>(elapsed_.size()), + static_cast<uint64_t>(worker_threads)); return true; } |