2 * Copyright 2015 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
14 #ifdef SK_BUILD_FOR_WIN
15 static const char* kBars[] = { ".", "o", "O" };
17 static const char* kBars[] = { "▁", "▂", "▃", "▄", "▅", "▆", "▇", "█" };
21 Stats(const SkTArray<double>& samples) {
22 int n = samples.count();
24 min = max = mean = var = median = 0;
30 for (int i = 0; i < n; i++) {
31 if (samples[i] < min) { min = samples[i]; }
32 if (samples[i] > max) { max = samples[i]; }
36 for (int i = 0 ; i < n; i++) {
42 for (int i = 0 ; i < n; i++) {
43 err += (samples[i] - mean) * (samples[i] - mean);
47 SkAutoTMalloc<double> sorted(n);
48 memcpy(sorted.get(), samples.begin(), n * sizeof(double));
49 SkTQSort(sorted.get(), sorted.get() + n - 1);
52 // Normalize samples to [min, max] in as many quanta as we have distinct bars to print.
53 for (int i = 0; i < n; i++) {
55 // All samples are the same value. Don't divide by zero.
56 plot.append(kBars[0]);
60 double s = samples[i];
63 s *= (SK_ARRAY_COUNT(kBars) - 1);
64 const size_t bar = (size_t)(s + 0.5);
65 SK_ALWAYSBREAK(bar < SK_ARRAY_COUNT(kBars));
66 plot.append(kBars[bar]);
72 double mean; // Estimate of population mean.
73 double var; // Estimate of population variance.
75 SkString plot; // A single-line bar chart (_not_ histogram) of the samples.