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 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 BenchmarkSuite.prototype.NotifyResult = function() { | 162 BenchmarkSuite.prototype.NotifyResult = function() { |
163 var mean = BenchmarkSuite.GeometricMean(this.results); | 163 var mean = BenchmarkSuite.GeometricMean(this.results); |
164 var score = this.reference / mean; | 164 var score = this.reference / mean; |
165 BenchmarkSuite.scores.push(score); | 165 BenchmarkSuite.scores.push(score); |
166 if (this.runner.NotifyResult) { | 166 if (this.runner.NotifyResult) { |
167 this.runner.NotifyResult(this.name, Math.round(100 * score)); | 167 this.runner.NotifyResult(this.name, Math.round(100 * score)); |
168 } | 168 } |
169 } | 169 } |
170 | 170 |
171 | 171 |
| 172 // Notifies the runner that running a benchmark resulted in an error. |
| 173 BenchmarkSuite.prototype.NotifyError = function(error) { |
| 174 if (this.runner.NotifyError) { |
| 175 this.runner.NotifyError(this.name, error); |
| 176 } |
| 177 if (this.runner.NotifyStep) { |
| 178 this.runner.NotifyStep(this.name); |
| 179 } |
| 180 } |
| 181 |
| 182 |
172 // Runs a single benchmark for at least a second and computes the | 183 // Runs a single benchmark for at least a second and computes the |
173 // average time it takes to run a single iteration. | 184 // average time it takes to run a single iteration. |
174 BenchmarkSuite.prototype.RunSingle = function(benchmark) { | 185 BenchmarkSuite.prototype.RunSingle = function(benchmark) { |
175 var elapsed = 0; | 186 var elapsed = 0; |
176 var start = new Date(); | 187 var start = new Date(); |
177 for (var n = 0; elapsed < 1000; n++) { | 188 for (var n = 0; elapsed < 1000; n++) { |
178 benchmark.run(); | 189 benchmark.run(); |
179 elapsed = new Date() - start; | 190 elapsed = new Date() - start; |
180 } | 191 } |
181 var usec = (elapsed * 1000) / n; | 192 var usec = (elapsed * 1000) / n; |
182 this.NotifyStep(new BenchmarkResult(benchmark, usec)); | 193 this.NotifyStep(new BenchmarkResult(benchmark, usec)); |
183 } | 194 } |
184 | 195 |
185 | 196 |
186 // This function starts running a suite, but stops between each | 197 // This function starts running a suite, but stops between each |
187 // individual benchmark in the suite and returns a continuation | 198 // individual benchmark in the suite and returns a continuation |
188 // function which can be invoked to run the next benchmark. Once the | 199 // function which can be invoked to run the next benchmark. Once the |
189 // last benchmark has been executed, null is returned. | 200 // last benchmark has been executed, null is returned. |
190 BenchmarkSuite.prototype.RunStep = function(runner) { | 201 BenchmarkSuite.prototype.RunStep = function(runner) { |
191 this.results = []; | 202 this.results = []; |
192 this.runner = runner; | 203 this.runner = runner; |
193 var length = this.benchmarks.length; | 204 var length = this.benchmarks.length; |
194 var index = 0; | 205 var index = 0; |
195 var suite = this; | 206 var suite = this; |
196 function RunNext() { | 207 function RunNext() { |
197 if (index < length) { | 208 if (index < length) { |
198 suite.RunSingle(suite.benchmarks[index++]); | 209 try { |
| 210 suite.RunSingle(suite.benchmarks[index++]); |
| 211 } catch (e) { |
| 212 suite.NotifyError(e); |
| 213 return null; |
| 214 } |
199 return RunNext; | 215 return RunNext; |
200 } | 216 } |
201 suite.NotifyResult(); | 217 suite.NotifyResult(); |
202 return null; | 218 return null; |
203 } | 219 } |
204 return RunNext(); | 220 return RunNext(); |
205 } | 221 } |
OLD | NEW |