Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Unified Diff: tools/Stats.h

Issue 390483002: nanobench: add a cute bar chart (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: size_t >= 0, duh Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « bench/nanobench.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/Stats.h
diff --git a/tools/Stats.h b/tools/Stats.h
index 5128897d8563e0df29fdc1dc82b2467766a9630d..67bd45d863737944fc83728daf25a31be801cf6d 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
« no previous file with comments | « bench/nanobench.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698