OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 /// An entrypoint used to run portions of analyzer and measure its performance. | 5 /// An entrypoint used to run portions of analyzer and measure its performance. |
6 library analyzer_cli.tool.perf; | 6 library analyzer_cli.tool.perf; |
7 | 7 |
8 import 'dart:async'; | 8 import 'dart:async'; |
9 import 'dart:io' show exit; | 9 import 'dart:io' show exit; |
10 | 10 |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 } | 180 } |
181 | 181 |
182 /// Scan [source] and return the first token produced by the scanner. | 182 /// Scan [source] and return the first token produced by the scanner. |
183 Token tokenize(Source source) { | 183 Token tokenize(Source source) { |
184 scanTimer.start(); | 184 scanTimer.start(); |
185 var contents = source.contents.data; | 185 var contents = source.contents.data; |
186 scanTotalChars += contents.length; | 186 scanTotalChars += contents.length; |
187 // TODO(sigmund): is there a way to scan from a random-access-file without | 187 // TODO(sigmund): is there a way to scan from a random-access-file without |
188 // first converting to String? | 188 // first converting to String? |
189 var scanner = new Scanner(source, new CharSequenceReader(contents), | 189 var scanner = new Scanner(source, new CharSequenceReader(contents), |
190 AnalysisErrorListener.NULL_LISTENER)..preserveComments = false; | 190 AnalysisErrorListener.NULL_LISTENER) |
| 191 ..preserveComments = false; |
191 var token = scanner.tokenize(); | 192 var token = scanner.tokenize(); |
192 scanTimer.stop(); | 193 scanTimer.stop(); |
193 return token; | 194 return token; |
194 } | 195 } |
195 | 196 |
196 /// Report that metric [name] took [time] micro-seconds to process | 197 /// Report that metric [name] took [time] micro-seconds to process |
197 /// [scanTotalChars] characters. | 198 /// [scanTotalChars] characters. |
198 void report(String name, int time) { | 199 void report(String name, int time) { |
199 var sb = new StringBuffer(); | 200 var sb = new StringBuffer(); |
200 sb.write('$name: $time us, ${time ~/ 1000} ms'); | 201 sb.write('$name: $time us, ${time ~/ 1000} ms'); |
201 sb.write(', ${scanTotalChars * 1000 ~/ time} chars/ms'); | 202 sb.write(', ${scanTotalChars * 1000 ~/ time} chars/ms'); |
202 print('$sb'); | 203 print('$sb'); |
203 } | 204 } |
OLD | NEW |