OLD | NEW |
1 // Copyright 2008 the V8 project authors. All rights reserved. | 1 // Copyright 2008 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 if (runner.NotifyStart) runner.NotifyStart(suite.name); | 113 if (runner.NotifyStart) runner.NotifyStart(suite.name); |
114 continuation = suite.RunStep(runner); | 114 continuation = suite.RunStep(runner); |
115 } | 115 } |
116 if (continuation && typeof window != 'undefined' && window.setTimeout) { | 116 if (continuation && typeof window != 'undefined' && window.setTimeout) { |
117 window.setTimeout(RunStep, 100); | 117 window.setTimeout(RunStep, 100); |
118 return; | 118 return; |
119 } | 119 } |
120 } | 120 } |
121 if (runner.NotifyScore) { | 121 if (runner.NotifyScore) { |
122 var score = BenchmarkSuite.GeometricMean(BenchmarkSuite.scores); | 122 var score = BenchmarkSuite.GeometricMean(BenchmarkSuite.scores); |
123 runner.NotifyScore(100 * score); | 123 var formatted = BenchmarkSuite.FormatScore(100 * score); |
| 124 runner.NotifyScore(formatted); |
124 } | 125 } |
125 } | 126 } |
126 RunStep(); | 127 RunStep(); |
127 } | 128 } |
128 | 129 |
129 | 130 |
130 // Counts the total number of registered benchmarks. Useful for | 131 // Counts the total number of registered benchmarks. Useful for |
131 // showing progress as a percentage. | 132 // showing progress as a percentage. |
132 BenchmarkSuite.CountBenchmarks = function() { | 133 BenchmarkSuite.CountBenchmarks = function() { |
133 var result = 0; | 134 var result = 0; |
134 var suites = BenchmarkSuite.suites; | 135 var suites = BenchmarkSuite.suites; |
135 for (var i = 0; i < suites.length; i++) { | 136 for (var i = 0; i < suites.length; i++) { |
136 result += suites[i].benchmarks.length; | 137 result += suites[i].benchmarks.length; |
137 } | 138 } |
138 return result; | 139 return result; |
139 } | 140 } |
140 | 141 |
141 | 142 |
142 // Computes the geometric mean of a set of numbers. | 143 // Computes the geometric mean of a set of numbers. |
143 BenchmarkSuite.GeometricMean = function(numbers) { | 144 BenchmarkSuite.GeometricMean = function(numbers) { |
144 var log = 0; | 145 var log = 0; |
145 for (var i = 0; i < numbers.length; i++) { | 146 for (var i = 0; i < numbers.length; i++) { |
146 log += Math.log(numbers[i]); | 147 log += Math.log(numbers[i]); |
147 } | 148 } |
148 return Math.pow(Math.E, log / numbers.length); | 149 return Math.pow(Math.E, log / numbers.length); |
149 } | 150 } |
150 | 151 |
151 | 152 |
| 153 // Converts a score value to a string with at least three significant |
| 154 // digits. |
| 155 BenchmarkSuite.FormatScore = function(value) { |
| 156 if (value > 100) { |
| 157 return value.toFixed(0); |
| 158 } else { |
| 159 return value.toPrecision(3); |
| 160 } |
| 161 } |
| 162 |
152 // Notifies the runner that we're done running a single benchmark in | 163 // Notifies the runner that we're done running a single benchmark in |
153 // the benchmark suite. This can be useful to report progress. | 164 // the benchmark suite. This can be useful to report progress. |
154 BenchmarkSuite.prototype.NotifyStep = function(result) { | 165 BenchmarkSuite.prototype.NotifyStep = function(result) { |
155 this.results.push(result); | 166 this.results.push(result); |
156 if (this.runner.NotifyStep) this.runner.NotifyStep(result.benchmark.name); | 167 if (this.runner.NotifyStep) this.runner.NotifyStep(result.benchmark.name); |
157 } | 168 } |
158 | 169 |
159 | 170 |
160 // Notifies the runner that we're done with running a suite and that | 171 // Notifies the runner that we're done with running a suite and that |
161 // we have a result which can be reported to the user if needed. | 172 // we have a result which can be reported to the user if needed. |
162 BenchmarkSuite.prototype.NotifyResult = function() { | 173 BenchmarkSuite.prototype.NotifyResult = function() { |
163 var mean = BenchmarkSuite.GeometricMean(this.results); | 174 var mean = BenchmarkSuite.GeometricMean(this.results); |
164 var score = this.reference / mean; | 175 var score = this.reference / mean; |
165 BenchmarkSuite.scores.push(score); | 176 BenchmarkSuite.scores.push(score); |
166 if (this.runner.NotifyResult) { | 177 if (this.runner.NotifyResult) { |
167 this.runner.NotifyResult(this.name, 100 * score); | 178 var formatted = BenchmarkSuite.FormatScore(100 * score); |
| 179 this.runner.NotifyResult(this.name, formatted); |
168 } | 180 } |
169 } | 181 } |
170 | 182 |
171 | 183 |
172 // Notifies the runner that running a benchmark resulted in an error. | 184 // Notifies the runner that running a benchmark resulted in an error. |
173 BenchmarkSuite.prototype.NotifyError = function(error) { | 185 BenchmarkSuite.prototype.NotifyError = function(error) { |
174 if (this.runner.NotifyError) { | 186 if (this.runner.NotifyError) { |
175 this.runner.NotifyError(this.name, error); | 187 this.runner.NotifyError(this.name, error); |
176 } | 188 } |
177 if (this.runner.NotifyStep) { | 189 if (this.runner.NotifyStep) { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 suite.NotifyError(e); | 224 suite.NotifyError(e); |
213 return null; | 225 return null; |
214 } | 226 } |
215 return RunNext; | 227 return RunNext; |
216 } | 228 } |
217 suite.NotifyResult(); | 229 suite.NotifyResult(); |
218 return null; | 230 return null; |
219 } | 231 } |
220 return RunNext(); | 232 return RunNext(); |
221 } | 233 } |
222 | |
223 | |
224 // Converts a score value to a string with at least three significant | |
225 // digits. | |
226 function formatScore(value) { | |
227 if (value > 100) { | |
228 return value.toFixed(0); | |
229 } else { | |
230 return value.toPrecision(3); | |
231 } | |
232 } | |
OLD | NEW |