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

Side by Side Diff: tools/Stats.h

Issue 392583005: nanobench: add --runOnce. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: add a note 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 unified diff | Download patch
« no previous file with comments | « bench/nanobench.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #ifndef Stats_DEFINED 1 #ifndef Stats_DEFINED
2 #define Stats_DEFINED 2 #define Stats_DEFINED
3 3
4 #include <math.h> 4 #include <math.h>
5 5
6 #include "SkString.h" 6 #include "SkString.h"
7 #include "SkTSort.h" 7 #include "SkTSort.h"
8 8
9 static const char* kBars[] = { "▁", "▂", "▃", "▄", "▅", "▆", "▇", "█" }; 9 static const char* kBars[] = { "▁", "▂", "▃", "▄", "▅", "▆", "▇", "█" };
10 10
(...skipping 16 matching lines...) Expand all
27 for (int i = 0 ; i < n; i++) { 27 for (int i = 0 ; i < n; i++) {
28 err += (samples[i] - mean) * (samples[i] - mean); 28 err += (samples[i] - mean) * (samples[i] - mean);
29 } 29 }
30 var = err / (n-1); 30 var = err / (n-1);
31 31
32 SkAutoTMalloc<double> sorted(n); 32 SkAutoTMalloc<double> sorted(n);
33 memcpy(sorted.get(), samples, n * sizeof(double)); 33 memcpy(sorted.get(), samples, n * sizeof(double));
34 SkTQSort(sorted.get(), sorted.get() + n - 1); 34 SkTQSort(sorted.get(), sorted.get() + n - 1);
35 median = sorted[n/2]; 35 median = sorted[n/2];
36 36
37 // Normalize samples to [min, max] in as many quanta as we have distinct bars to print.
37 for (int i = 0; i < n; i++) { 38 for (int i = 0; i < n; i++) {
39 if (min == max) {
40 // All samples are the same value. Don't divide by zero.
41 plot.append(kBars[0]);
42 continue;
43 }
44
38 double s = samples[i]; 45 double s = samples[i];
39 // Normalize samples to [min, max] in as many quanta as we have dist inct bars to print.
40 s -= min; 46 s -= min;
41 s /= (max - min); 47 s /= (max - min);
42 s *= (SK_ARRAY_COUNT(kBars) - 1); 48 s *= (SK_ARRAY_COUNT(kBars) - 1);
43 const size_t bar = (size_t)round(s); 49 const size_t bar = (size_t)round(s);
44 SK_ALWAYSBREAK(bar < SK_ARRAY_COUNT(kBars)); 50 SK_ALWAYSBREAK(bar < SK_ARRAY_COUNT(kBars));
45 plot.append(kBars[bar]); 51 plot.append(kBars[bar]);
46 } 52 }
47 } 53 }
48 54
49 double min; 55 double min;
50 double max; 56 double max;
51 double mean; // Estimate of population mean. 57 double mean; // Estimate of population mean.
52 double var; // Estimate of population variance. 58 double var; // Estimate of population variance.
53 double median; 59 double median;
54 SkString plot; // A single-line bar chart (_not_ histogram) of the samples. 60 SkString plot; // A single-line bar chart (_not_ histogram) of the samples.
55 }; 61 };
56 62
57 #endif//Stats_DEFINED 63 #endif//Stats_DEFINED
OLDNEW
« 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