diff options
-rw-r--r-- | bench/nanobench.cpp | 5 | ||||
-rw-r--r-- | tools/Stats.h | 21 |
2 files changed, 22 insertions, 4 deletions
diff --git a/bench/nanobench.cpp b/bench/nanobench.cpp index 71a412d19d..3f34740b69 100644 --- a/bench/nanobench.cpp +++ b/bench/nanobench.cpp @@ -238,7 +238,7 @@ int tool_main(int argc, char** argv) { } else if (FLAGS_quiet) { SkDebugf("median\tbench\tconfig\n"); } else { - SkDebugf("loops\tmin\tmedian\tmean\tmax\tstddev\tconfig\tbench\n"); + SkDebugf("loops\tmin\tmedian\tmean\tmax\tstddev\tsamples\tconfig\tbench\n"); } for (const BenchRegistry* r = BenchRegistry::Head(); r != NULL; r = r->next()) { @@ -277,13 +277,14 @@ int tool_main(int argc, char** argv) { SkDebugf("%s\t%s\t%s\n", humanize(stats.median).c_str(), bench->getName(), config); } else { const double stddev_percent = 100 * sqrt(stats.var) / stats.mean; - SkDebugf("%d\t%s\t%s\t%s\t%s\t%.0f%%\t%s\t%s\n" + SkDebugf("%d\t%s\t%s\t%s\t%s\t%.0f%%\t%s\t%s\t%s\n" , loops , humanize(stats.min).c_str() , humanize(stats.median).c_str() , humanize(stats.mean).c_str() , humanize(stats.max).c_str() , stddev_percent + , stats.plot.c_str() , config , bench->getName() ); diff --git a/tools/Stats.h b/tools/Stats.h index 5128897d85..67bd45d863 100644 --- a/tools/Stats.h +++ b/tools/Stats.h @@ -1,8 +1,13 @@ #ifndef Stats_DEFINED #define Stats_DEFINED +#include <math.h> + +#include "SkString.h" #include "SkTSort.h" +static const char* kBars[] = { "▁", "▂", "▃", "▄", "▅", "▆", "▇", "█" }; + struct Stats { Stats(const double samples[], int n) { min = samples[0]; @@ -28,13 +33,25 @@ struct Stats { memcpy(sorted.get(), samples, n * sizeof(double)); SkTQSort(sorted.get(), sorted.get() + n - 1); median = sorted[n/2]; + + for (int i = 0; i < n; i++) { + double s = samples[i]; + // Normalize samples to [min, max] in as many quanta as we have distinct bars to print. + s -= min; + s /= (max - min); + s *= (SK_ARRAY_COUNT(kBars) - 1); + const size_t bar = (size_t)round(s); + SK_ALWAYSBREAK(bar < SK_ARRAY_COUNT(kBars)); + plot.append(kBars[bar]); + } } double min; double max; - double mean; // Estimate of population mean. - double var; // Estimate of population variance. + double mean; // Estimate of population mean. + double var; // Estimate of population variance. double median; + SkString plot; // A single-line bar chart (_not_ histogram) of the samples. }; #endif//Stats_DEFINED |