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

Side by Side Diff: test/perf/compare.dart

Issue 55143003: webui fixes for 0.8.9 (Closed) Base URL: git@github.com:dart-lang/web-ui.git@master
Patch Set: Created 7 years, 1 month 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
OLDNEW
1 #!/usr/bin/env dart 1 #!/usr/bin/env dart
2 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 2 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
3 // for details. All rights reserved. Use of this source code is governed by a 3 // for details. All rights reserved. Use of this source code is governed by a
4 // BSD-style license that can be found in the LICENSE file. 4 // BSD-style license that can be found in the LICENSE file.
5 5
6 /** 6 /**
7 * Script that prints in a table format a comparison of two benchmark results. 7 * Script that prints in a table format a comparison of two benchmark results.
8 * The input is given as two json files containing the benchmark results. 8 * The input is given as two json files containing the benchmark results.
9 */ 9 */
10 library test.perf.compare; 10 library test.perf.compare;
11 11
12 import 'dart:io'; 12 import 'dart:io';
13 import 'dart:json' as json; 13 import 'dart:convert' show JSON;
14 import 'dart:math' as math; 14 import 'dart:math' as math;
15 15
16 main() { 16 main(args) {
17 var args = new Options().arguments;
18 if (args.length < 2) { 17 if (args.length < 2) {
19 print('usage: compare.dart results1.json results2.json [filter]'); 18 print('usage: compare.dart results1.json results2.json [filter]');
20 exit(1); 19 exit(1);
21 } 20 }
22 21
23 var path1 = args[0]; 22 var path1 = args[0];
24 var path2 = args[1]; 23 var path2 = args[1];
25 var file1 = new File(path1).readAsStringSync(); 24 var file1 = new File(path1).readAsStringSync();
26 var file2 = new File(path2).readAsStringSync(); 25 var file2 = new File(path2).readAsStringSync();
27 var filter = args.length > 2 ? new RegExp(args[2]) : null; 26 var filter = args.length > 2 ? new RegExp(args[2]) : null;
28 27
29 var results = []; 28 var results = [];
30 var map1 = json.parse(file1); 29 var map1 = JSON.decode(file1);
31 var map2 = json.parse(file2); 30 var map2 = JSON.decode(file2);
32 31
33 for (var key in map1.keys) { 32 for (var key in map1.keys) {
34 if (map2.containsKey(key)) { 33 if (map2.containsKey(key)) {
35 results.add(new ResultPair(key, map1[key], map2[key])); 34 results.add(new ResultPair(key, map1[key], map2[key]));
36 } else { 35 } else {
37 results.add(new ResultPair(key, map1[key], null)); 36 results.add(new ResultPair(key, map1[key], null));
38 } 37 }
39 } 38 }
40 39
41 for (var key in map2.keys) { 40 for (var key in map2.keys) {
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 num get factor => score1 == null || score2 == null ? null 98 num get factor => score1 == null || score2 == null ? null
100 : ((score2 - score1) * 100.0) / score1; 99 : ((score2 - score1) * 100.0) / score1;
101 100
102 ResultPair(this.name, double time1, double time2) 101 ResultPair(this.name, double time1, double time2)
103 : this.time1 = time1, this.time2 = time2, 102 : this.time1 = time1, this.time2 = time2,
104 score1 = time1 == null ? null : 1000000.0 / time1, 103 score1 = time1 == null ? null : 1000000.0 / time1,
105 score2 = time2 == null ? null : 1000000.0 / time2; 104 score2 = time2 == null ? null : 1000000.0 / time2;
106 105
107 String toString() { 106 String toString() {
108 var buff = new StringBuffer(); 107 var buff = new StringBuffer();
109 buff.add(name); 108 buff.write(name);
110 _ensureColumn(buff, 30); 109 _ensureColumn(buff, 30);
111 _addNumber(buff, score1, 45); 110 _addNumber(buff, score1, 45);
112 _addNumber(buff, score2, 60); 111 _addNumber(buff, score2, 60);
113 _addNumber(buff, factor, 75, color: true); 112 _addNumber(buff, factor, 75, color: true);
114 return buff.toString(); 113 return buff.toString();
115 } 114 }
116 115
117 int compareTo(ResultPair other) { 116 int compareTo(ResultPair other) {
118 if (name.startsWith('dart') && other.name.startsWith('js ')) return 1; 117 if (name.startsWith('dart') && other.name.startsWith('js ')) return 1;
119 if (name.startsWith('js ') && other.name.startsWith('dart')) return -1; 118 if (name.startsWith('js ') && other.name.startsWith('dart')) return -1;
120 if (factor != null && other.factor != null) { 119 if (factor != null && other.factor != null) {
121 var res = factor.compareTo(other.factor); 120 var res = factor.compareTo(other.factor);
122 if (res != 0) return res; 121 if (res != 0) return res;
123 } 122 }
124 return name.compareTo(other.name); 123 return name.compareTo(other.name);
125 } 124 }
126 } 125 }
127 126
128 _printLine(String col0, String col1, String col2, String col3) { 127 _printLine(String col0, String col1, String col2, String col3) {
129 var buff = new StringBuffer(); 128 var buff = new StringBuffer();
130 buff.add(col0); 129 buff.write(col0);
131 _ensureColumn(buff, 30); 130 _ensureColumn(buff, 30);
132 _padRight(buff, col1, 45); 131 _padRight(buff, col1, 45);
133 _padRight(buff, col2, 60); 132 _padRight(buff, col2, 60);
134 _padRight(buff, col3, 75); 133 _padRight(buff, col3, 75);
135 print(buff.toString()); 134 print(buff.toString());
136 } 135 }
137 136
138 _ensureColumn(StringBuffer buff, int ensure) { 137 _ensureColumn(StringBuffer buff, int ensure) {
139 while (buff.length < ensure) { 138 while (buff.length < ensure) {
140 buff.add(' '); 139 buff.write(' ');
141 } 140 }
142 } 141 }
143 142
144 _addNumber(StringBuffer buff, num value, int ensure, {bool color: false}) { 143 _addNumber(StringBuffer buff, num value, int ensure, {bool color: false}) {
145 var str; 144 var str;
146 if (value == null) { 145 if (value == null) {
147 str = '--'; 146 str = '--';
148 } else { 147 } else {
149 str = value.toStringAsFixed(value >= 100 ? 0 : (value >= 10 ? 1 : 2)); 148 str = value.toStringAsFixed(value >= 100 ? 0 : (value >= 10 ? 1 : 2));
150 } 149 }
151 150
152 while (buff.length + str.length < ensure) { 151 while (buff.length + str.length < ensure) {
153 buff.add(' '); 152 buff.write(' ');
154 } 153 }
155 if (color) _addColor(buff, value); 154 if (color) _addColor(buff, value);
156 buff.add(str); 155 buff.write(str);
157 if (color) _removeColor(buff, value); 156 if (color) _removeColor(buff, value);
158 } 157 }
159 158
160 _addColor(StringBuffer buff, num value) { 159 _addColor(StringBuffer buff, num value) {
161 if (value == null || value.abs() < 2) return; 160 if (value == null || value.abs() < 2) return;
162 var color; 161 var color;
163 if (value >= 2 && value < 7) { 162 if (value >= 2 && value < 7) {
164 color = ''; 163 color = '';
165 } else if (value >= 7) { 164 } else if (value >= 7) {
166 color = ''; 165 color = '';
167 } else if (value <= -2 && value > -7) { 166 } else if (value <= -2 && value > -7) {
168 color = ''; 167 color = '';
169 } else if (value <= -7) { 168 } else if (value <= -7) {
170 color = ''; 169 color = '';
171 } 170 }
172 buff.add(color); 171 buff.write(color);
173 } 172 }
174 173
175 _removeColor(StringBuffer buff, num value) { 174 _removeColor(StringBuffer buff, num value) {
176 if (value == null || value.abs() < 2) return; 175 if (value == null || value.abs() < 2) return;
177 buff.add(''); 176 buff.write('');
178 } 177 }
179 178
180 _padRight(StringBuffer buff, String str, int ensure) { 179 _padRight(StringBuffer buff, String str, int ensure) {
181 while (buff.length + str.length < ensure) { 180 while (buff.length + str.length < ensure) {
182 buff.add(' '); 181 buff.write(' ');
183 } 182 }
184 buff.add(str); 183 buff.write(str);
185 } 184 }
186 185
187 _geomean(List<num> numbers) { 186 _geomean(List<num> numbers) {
188 var log = 0.0; 187 var log = 0.0;
189 for (var n in numbers) { 188 for (var n in numbers) {
190 log += math.log(n); 189 log += math.log(n);
191 } 190 }
192 return math.pow(math.E, log / numbers.length); 191 return math.pow(math.E, log / numbers.length);
193 } 192 }
OLDNEW
« pubspec.yaml ('K') | « test/paths_test.dart ('k') | test/perf/perf.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698