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

Side by Side Diff: sky/benchmarks/resources/runner.sky

Issue 1216823002: Remove sky/benchmarks (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 6 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 | « sky/benchmarks/resources/fakesky.dart ('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
(Empty)
1 <script>
2 function PerfRunner(options) {
3 this.unit_ = options.unit || "ms";
4 this.iterationsRemaining_ = options.iterations || 10;
5 this.results_ = [];
6 this.setup_ = options.setup;
7 this.logLines_ = [];
8 }
9
10 PerfRunner.prototype.log = function(line) {
11 this.logLines_.push(line);
12 };
13
14 PerfRunner.prototype.recordResult = function(result) {
15 this.results_.push(result);
16 };
17
18 PerfRunner.prototype.runAsync = function(test) {
19 var self = this;
20 window.setTimeout(function() {
21 if (self.setup_) {
22 var setup = self.setup_;
23 setup();
24 }
25
26 var startTime = Date.now();
27 test(function() {
28 var endTime = Date.now();
29
30 self.recordResult(endTime - startTime);
31 if (--self.iterationsRemaining_ > 0)
32 self.runAsync(test);
33 else
34 self.finish();
35 });
36 });
37 };
38
39 PerfRunner.prototype.computeStatistics = function() {
40 var data = this.results_.slice();
41
42 // Add values from the smallest to the largest to avoid the loss of significan ce
43 data.sort(function(a, b) { return a - b; });
44
45 var middle = Math.floor(data.length / 2);
46 var stats = {
47 min: data[0],
48 max: data[data.length - 1],
49 median: data.length % 2 ? data[middle] : (data[middle - 1] + data[middle]) / 2,
50 };
51
52 // Compute the mean and variance using Knuth's online algorithm (has good nume rical stability).
53 var squareSum = 0;
54 stats.values = this.results_;
55 stats.mean = 0;
56 for (var i = 0; i < data.length; ++i) {
57 var x = data[i];
58 var delta = x - stats.mean;
59 var sweep = i + 1.0;
60 stats.mean += delta / sweep;
61 squareSum += delta * (x - stats.mean);
62 }
63 stats.variance = data.length <= 1 ? 0 : squareSum / (data.length - 1);
64 stats.stdev = Math.sqrt(stats.variance);
65 stats.unit = this.unit_;
66
67 return stats;
68 };
69
70 PerfRunner.prototype.logStatistics = function(title) {
71 var stats = this.computeStatistics();
72 this.log("");
73 this.log(title);
74 if (stats.values)
75 this.log("values " + stats.values.join(", ") + " " + stats.unit);
76 this.log("avg " + stats.mean + " " + stats.unit);
77 this.log("median " + stats.median + " " + stats.unit);
78 this.log("stdev " + stats.stdev + " " + stats.unit);
79 this.log("min " + stats.min + " " + stats.unit);
80 this.log("max " + stats.max + " " + stats.unit);
81 };
82
83 PerfRunner.prototype.finish = function () {
84 this.logStatistics("Time:");
85 internals.notifyTestComplete(this.logLines_.join('\n'));
86 }
87
88 module.exports = PerfRunner;
89 </script>
OLDNEW
« no previous file with comments | « sky/benchmarks/resources/fakesky.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698