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

Side by Side Diff: tests/benchmark_smoke/benchmark_base.dart

Issue 12212200: "Reverting 18531" (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « sdk/lib/html/dartium/html_dartium.dart ('k') | tests/benchmark_smoke/benchmark_lib.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 new Timer(const Duration(milliseconds: 25), 134 window.setTimeout(() => runBenchmarksHelper(remainingBenchmarks), 25);
135 () => runBenchmarksHelper(remainingBenchmarks));
136 } else if (remainingBenchmarks.length == 0) { 135 } else if (remainingBenchmarks.length == 0) {
137 // We've run all of the benchmarks. Update the page with the score. 136 // We've run all of the benchmarks. Update the page with the score.
138 BENCHMARK_VIEW.setScore(geometricMean(scores)); 137 BENCHMARK_VIEW.setScore(geometricMean(scores));
139 } 138 }
140 } 139 }
141 140
142 /** Store the results of a single benchmark run. */ 141 /** Store the results of a single benchmark run. */
143 updateIndividualScore(String name, num score) { 142 updateIndividualScore(String name, num score) {
144 scores.add(score); 143 scores.add(score);
145 BENCHMARK_VIEW.incrementProgress(name, score, totalBenchmarks); 144 BENCHMARK_VIEW.incrementProgress(name, score, totalBenchmarks);
146 } 145 }
147 146
148 /** Computes the geometric mean of a set of numbers. */ 147 /** Computes the geometric mean of a set of numbers. */
149 geometricMean(numbers) { 148 geometricMean(numbers) {
150 num log = 0; 149 num log = 0;
151 for (num n in numbers) { 150 for (num n in numbers) {
152 log += Math.log(n); 151 log += Math.log(n);
153 } 152 }
154 return Math.pow(Math.E, log / numbers.length); 153 return Math.pow(Math.E, log / numbers.length);
(...skipping 11 matching lines...) Expand all
166 165
167 BenchmarkView._internal(); 166 BenchmarkView._internal();
168 167
169 /** Update the page HTML to show the calculated score. */ 168 /** Update the page HTML to show the calculated score. */
170 setScore(num score) { 169 setScore(num score) {
171 String newScore = formatScore(score * 100.0); 170 String newScore = formatScore(score * 100.0);
172 Element body = document.queryAll("body")[0]; 171 Element body = document.queryAll("body")[0];
173 body.nodes.add( 172 body.nodes.add(
174 new Element.html("<p id='testResultScore'>Score: $newScore</p>")); 173 new Element.html("<p id='testResultScore'>Score: $newScore</p>"));
175 } 174 }
176 175
177 /** 176 /**
178 * Update the page HTML to show how much progress we've made through the 177 * Update the page HTML to show how much progress we've made through the
179 * benchmarks. 178 * benchmarks.
180 */ 179 */
181 incrementProgress(String name, num score, num totalBenchmarks) { 180 incrementProgress(String name, num score, num totalBenchmarks) {
182 String newScore = formatScore(score * 100.0); 181 String newScore = formatScore(score * 100.0);
183 numCompleted++; 182 numCompleted++;
184 // Slightly incorrect (truncating) percentage, but this is just to show 183 // Slightly incorrect (truncating) percentage, but this is just to show
185 // the user we're making progress. 184 // the user we're making progress.
186 num percentage = 100 * numCompleted ~/ totalBenchmarks; 185 num percentage = 100 * numCompleted ~/ totalBenchmarks;
187 } 186 }
188 187
189 /** 188 /**
190 * Rounds the score to have at least three significant digits (hopefully) 189 * Rounds the score to have at least three significant digits (hopefully)
191 * helping readability of the scores. 190 * helping readability of the scores.
192 */ 191 */
193 String formatScore(num value) { 192 String formatScore(num value) {
194 if (value > 100) { 193 if (value > 100) {
195 return value.toStringAsFixed(0); 194 return value.toStringAsFixed(0);
196 } else { 195 } else {
197 return value.toStringAsFixed(2); 196 return value.toStringAsFixed(2);
198 } 197 }
199 } 198 }
200 } 199 }
OLDNEW
« no previous file with comments | « sdk/lib/html/dartium/html_dartium.dart ('k') | tests/benchmark_smoke/benchmark_lib.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698