diff options
author | mtklein <mtklein@chromium.org> | 2014-07-11 11:57:07 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-07-11 11:57:07 -0700 |
commit | 5d9d10e8217d2138b5514a4d4216f95373240942 (patch) | |
tree | 672c0e7d1963b85b23c4e3246ac4bdf81f1643fe /tools/Stats.h | |
parent | ef0fd61dc2ea50ce29b1fe0feed473479b32e42c (diff) |
nanobench: add a cute bar chart
Give this a try? Helpful, or gets in the way?
BUG=skia:
R=krajcevski@google.com, mtklein@google.com
Author: mtklein@chromium.org
Review URL: https://codereview.chromium.org/390483002
Diffstat (limited to 'tools/Stats.h')
-rw-r--r-- | tools/Stats.h | 21 |
1 files changed, 19 insertions, 2 deletions
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 |