From ef6bbbd06374cf7ef175c780ec9ac87c43386532 Mon Sep 17 00:00:00 2001 From: Mike Klein Date: Thu, 5 Jan 2017 14:23:57 -0500 Subject: [PATCH] monobench: don't sort the Bench vector while iterating through it... We sort to display Bench results in an ascending order, but we're doing this while iterating through the bench vector. This is probably undefined, and really screws up the sample distribution in practice. Slow benches run more often. Instead, copy the results of the benches to a new Result vector to sort and display. Each bench now gets its fair share of samples. Change-Id: I4ead0d9d69af271c9971eedb35604a4b3bca0784 Reviewed-on: https://skia-review.googlesource.com/6623 Reviewed-by: Mike Klein Reviewed-by: Herb Derby Commit-Queue: Mike Klein --- tools/monobench.cpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/tools/monobench.cpp b/tools/monobench.cpp index 722ae91..fa0de8a 100644 --- a/tools/monobench.cpp +++ b/tools/monobench.cpp @@ -111,15 +111,22 @@ int main(int argc, char** argv) { bench.best = std::min(bench.best, elapsed / loops); samples++; - std::sort(benches.begin(), benches.end(), [](const Bench& a, const Bench& b) { + struct Result { const char* name; ns best; }; + std::vector sorted(benches.size()); + for (size_t i = 0; i < benches.size(); i++) { + sorted[i].name = benches[i].name.c_str(); + sorted[i].best = benches[i].best; + } + std::sort(sorted.begin(), sorted.end(), [](const Result& a, const Result& b) { return a.best < b.best; }); + SkDebugf("%s%d", kSkOverwriteLine, samples); - for (auto& bench : benches) { - if (benches.size() == 1) { - SkDebugf(" %s %gns" , bench.name.c_str(), bench.best.count()); + for (auto& result : sorted) { + if (sorted.size() == 1) { + SkDebugf(" %s %gns" , result.name, result.best.count()); } else { - SkDebugf(" %s %.3gx", bench.name.c_str(), bench.best / benches[0].best); + SkDebugf(" %s %.3gx", result.name, result.best / sorted[0].best); } } break; -- 2.7.4