| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 part of benchmark_lib; | 5 part of benchmark_lib; |
| 6 | 6 |
| 7 /** Accessors for our Singleton variables. */ | 7 /** Accessors for our Singleton variables. */ |
| 8 BenchmarkSuite get BENCHMARK_SUITE { | 8 BenchmarkSuite get BENCHMARK_SUITE { |
| 9 if (BenchmarkSuite._ONLY == null) { | 9 if (BenchmarkSuite._ONLY == null) { |
| 10 BenchmarkSuite._ONLY = new BenchmarkSuite._internal(); | 10 BenchmarkSuite._ONLY = new BenchmarkSuite._internal(); |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 Map<String, int> normalizingDict = {'Smoketest': 100}; | 87 Map<String, int> normalizingDict = {'Smoketest': 100}; |
| 88 score = score / normalizingDict[name]; | 88 score = score / normalizingDict[name]; |
| 89 BENCHMARK_SUITE.updateIndividualScore(name, score); | 89 BENCHMARK_SUITE.updateIndividualScore(name, score); |
| 90 } | 90 } |
| 91 } | 91 } |
| 92 | 92 |
| 93 /** The controller class that runs all of the benchmarks. */ | 93 /** The controller class that runs all of the benchmarks. */ |
| 94 class BenchmarkSuite { | 94 class BenchmarkSuite { |
| 95 /** The set of benchmarks that have yet to run. */ | 95 /** The set of benchmarks that have yet to run. */ |
| 96 List<Function> benchmarks; | 96 List<Function> benchmarks; |
| 97 | 97 |
| 98 /** | 98 /** |
| 99 * The set of scores from the benchmarks that have already run. (Used for | 99 * The set of scores from the benchmarks that have already run. (Used for |
| 100 * calculating the Geometric mean). | 100 * calculating the Geometric mean). |
| 101 */ | 101 */ |
| 102 List<num> scores; | 102 List<num> scores; |
| 103 | 103 |
| 104 /** The total number of benchmarks we will be running. */ | 104 /** The total number of benchmarks we will be running. */ |
| 105 int totalBenchmarks; | 105 int totalBenchmarks; |
| 106 | 106 |
| 107 /** Singleton pattern: There's only one BenchmarkSuite. */ | 107 /** Singleton pattern: There's only one BenchmarkSuite. */ |
| 108 static BenchmarkSuite _ONLY = null; | 108 static BenchmarkSuite _ONLY = null; |
| 109 | 109 |
| 110 BenchmarkSuite._internal() { | 110 BenchmarkSuite._internal() { |
| 111 scores = []; | 111 scores = []; |
| 112 benchmarks = [() => Smoketest.main()]; | 112 benchmarks = [() => Smoketest.main()]; |
| 113 totalBenchmarks = benchmarks.length; | 113 totalBenchmarks = benchmarks.length; |
| 114 } | 114 } |
| 115 | 115 |
| 116 /** Run all of the benchmarks that we have in our benchmarks list. */ | 116 /** Run all of the benchmarks that we have in our benchmarks list. */ |
| 117 runBenchmarks() { | 117 runBenchmarks() { |
| 118 runBenchmarksHelper(benchmarks); | 118 runBenchmarksHelper(benchmarks); |
| 119 } | 119 } |
| 120 | 120 |
| 121 /** | 121 /** |
| 122 * Run the remaining benchmarks in our list. We chain the calls providing | 122 * Run the remaining benchmarks in our list. We chain the calls providing |
| 123 * little breaks for the main page to gain control, so we don't force the | 123 * little breaks for the main page to gain control, so we don't force the |
| 124 * entire page to hang the whole time. | 124 * entire page to hang the whole time. |
| 125 */ | 125 */ |
| 126 runBenchmarksHelper(List<Function> remainingBenchmarks) { | 126 runBenchmarksHelper(List<Function> remainingBenchmarks) { |
| 127 // Remove the last benchmark, and run it. | 127 // Remove the last benchmark, and run it. |
| 128 var benchmark = remainingBenchmarks.removeLast(); | 128 var benchmark = remainingBenchmarks.removeLast(); |
| 129 benchmark(); | 129 benchmark(); |
| 130 if (remainingBenchmarks.length > 0) { | 130 if (remainingBenchmarks.length > 0) { |
| 131 /* Provide small breaks between each benchmark, so that the browser | 131 /* Provide small breaks between each benchmark, so that the browser |
| 132 doesn't get unhappy about long running scripts, and so the user | 132 doesn't get unhappy about long running scripts, and so the user |
| 133 can regain control of the UI to kill the page as needed. */ | 133 can regain control of the UI to kill the page as needed. */ |
| 134 window.setTimeout(() => runBenchmarksHelper(remainingBenchmarks), 25); | 134 new Timer(const Duration(milliseconds: 25), |
| 135 () => runBenchmarksHelper(remainingBenchmarks)); |
| 135 } else if (remainingBenchmarks.length == 0) { | 136 } else if (remainingBenchmarks.length == 0) { |
| 136 // We've run all of the benchmarks. Update the page with the score. | 137 // We've run all of the benchmarks. Update the page with the score. |
| 137 BENCHMARK_VIEW.setScore(geometricMean(scores)); | 138 BENCHMARK_VIEW.setScore(geometricMean(scores)); |
| 138 } | 139 } |
| 139 } | 140 } |
| 140 | 141 |
| 141 /** Store the results of a single benchmark run. */ | 142 /** Store the results of a single benchmark run. */ |
| 142 updateIndividualScore(String name, num score) { | 143 updateIndividualScore(String name, num score) { |
| 143 scores.add(score); | 144 scores.add(score); |
| 144 BENCHMARK_VIEW.incrementProgress(name, score, totalBenchmarks); | 145 BENCHMARK_VIEW.incrementProgress(name, score, totalBenchmarks); |
| 145 } | 146 } |
| 146 | 147 |
| 147 /** Computes the geometric mean of a set of numbers. */ | 148 /** Computes the geometric mean of a set of numbers. */ |
| 148 geometricMean(numbers) { | 149 geometricMean(numbers) { |
| 149 num log = 0; | 150 num log = 0; |
| 150 for (num n in numbers) { | 151 for (num n in numbers) { |
| 151 log += Math.log(n); | 152 log += Math.log(n); |
| 152 } | 153 } |
| 153 return Math.pow(Math.E, log / numbers.length); | 154 return Math.pow(Math.E, log / numbers.length); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 165 | 166 |
| 166 BenchmarkView._internal(); | 167 BenchmarkView._internal(); |
| 167 | 168 |
| 168 /** Update the page HTML to show the calculated score. */ | 169 /** Update the page HTML to show the calculated score. */ |
| 169 setScore(num score) { | 170 setScore(num score) { |
| 170 String newScore = formatScore(score * 100.0); | 171 String newScore = formatScore(score * 100.0); |
| 171 Element body = document.queryAll("body")[0]; | 172 Element body = document.queryAll("body")[0]; |
| 172 body.nodes.add( | 173 body.nodes.add( |
| 173 new Element.html("<p id='testResultScore'>Score: $newScore</p>")); | 174 new Element.html("<p id='testResultScore'>Score: $newScore</p>")); |
| 174 } | 175 } |
| 175 | 176 |
| 176 /** | 177 /** |
| 177 * Update the page HTML to show how much progress we've made through the | 178 * Update the page HTML to show how much progress we've made through the |
| 178 * benchmarks. | 179 * benchmarks. |
| 179 */ | 180 */ |
| 180 incrementProgress(String name, num score, num totalBenchmarks) { | 181 incrementProgress(String name, num score, num totalBenchmarks) { |
| 181 String newScore = formatScore(score * 100.0); | 182 String newScore = formatScore(score * 100.0); |
| 182 numCompleted++; | 183 numCompleted++; |
| 183 // Slightly incorrect (truncating) percentage, but this is just to show | 184 // Slightly incorrect (truncating) percentage, but this is just to show |
| 184 // the user we're making progress. | 185 // the user we're making progress. |
| 185 num percentage = 100 * numCompleted ~/ totalBenchmarks; | 186 num percentage = 100 * numCompleted ~/ totalBenchmarks; |
| 186 } | 187 } |
| 187 | 188 |
| 188 /** | 189 /** |
| 189 * Rounds the score to have at least three significant digits (hopefully) | 190 * Rounds the score to have at least three significant digits (hopefully) |
| 190 * helping readability of the scores. | 191 * helping readability of the scores. |
| 191 */ | 192 */ |
| 192 String formatScore(num value) { | 193 String formatScore(num value) { |
| 193 if (value > 100) { | 194 if (value > 100) { |
| 194 return value.toStringAsFixed(0); | 195 return value.toStringAsFixed(0); |
| 195 } else { | 196 } else { |
| 196 return value.toStringAsFixed(2); | 197 return value.toStringAsFixed(2); |
| 197 } | 198 } |
| 198 } | 199 } |
| 199 } | 200 } |
| OLD | NEW |