OLD | NEW |
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, 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 fasta and measure its performance. | 5 /// An entrypoint used to run portions of fasta and measure its performance. |
6 library front_end.tool.fasta_perf; | 6 library front_end.tool.fasta_perf; |
7 | 7 |
8 import 'dart:async'; | 8 import 'dart:async'; |
9 import 'dart:io'; | 9 import 'dart:io'; |
10 | 10 |
11 import 'package:front_end/src/fasta/analyzer/ast_builder.dart'; | 11 import 'package:front_end/src/fasta/analyzer/ast_builder.dart'; |
12 import 'package:front_end/src/fasta/ast_kind.dart' show AstKind; | |
13 import 'package:front_end/src/fasta/dill/dill_target.dart' show DillTarget; | 12 import 'package:front_end/src/fasta/dill/dill_target.dart' show DillTarget; |
14 import 'package:front_end/src/fasta/kernel/kernel_target.dart' | 13 import 'package:front_end/src/fasta/kernel/kernel_target.dart' |
15 show KernelTarget; | 14 show KernelTarget; |
16 import 'package:front_end/src/fasta/parser.dart'; | 15 import 'package:front_end/src/fasta/parser.dart'; |
17 import 'package:front_end/src/fasta/scanner.dart'; | 16 import 'package:front_end/src/fasta/scanner.dart'; |
18 import 'package:front_end/src/fasta/scanner/io.dart' show readBytesFromFileSync; | 17 import 'package:front_end/src/fasta/scanner/io.dart' show readBytesFromFileSync; |
19 import 'package:front_end/src/fasta/scanner/precedence.dart'; | 18 import 'package:front_end/src/fasta/scanner/precedence.dart'; |
20 import 'package:front_end/src/fasta/source/scope_listener.dart' show Scope; | 19 import 'package:front_end/src/fasta/source/scope_listener.dart' show Scope; |
21 import 'package:front_end/src/fasta/ticker.dart' show Ticker; | 20 import 'package:front_end/src/fasta/ticker.dart' show Ticker; |
22 import 'package:front_end/src/fasta/translate_uri.dart' show TranslateUri; | 21 import 'package:front_end/src/fasta/translate_uri.dart' show TranslateUri; |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
269 Uri.parse('dart:typed_data'), | 268 Uri.parse('dart:typed_data'), |
270 ]; | 269 ]; |
271 entrypoints.forEach(kernelTarget.read); | 270 entrypoints.forEach(kernelTarget.read); |
272 | 271 |
273 if (!compileSdk) { | 272 if (!compileSdk) { |
274 dillTarget.read( | 273 dillTarget.read( |
275 Uri.base.resolve(Platform.resolvedExecutable).resolve('platform.dill')); | 274 Uri.base.resolve(Platform.resolvedExecutable).resolve('platform.dill')); |
276 } | 275 } |
277 await dillTarget.writeOutline(null); | 276 await dillTarget.writeOutline(null); |
278 var program = await kernelTarget.writeOutline(null); | 277 var program = await kernelTarget.writeOutline(null); |
279 program = await kernelTarget.writeProgram(null, AstKind.Kernel); | 278 program = await kernelTarget.writeProgram(null); |
280 if (kernelTarget.errors.isNotEmpty) { | 279 if (kernelTarget.errors.isNotEmpty) { |
281 throw kernelTarget.errors.first; | 280 throw kernelTarget.errors.first; |
282 } | 281 } |
283 timer.stop(); | 282 timer.stop(); |
284 report('kernel_gen_e2e', timer.elapsedMicroseconds); | 283 report('kernel_gen_e2e', timer.elapsedMicroseconds); |
285 return program; | 284 return program; |
286 } | 285 } |
287 | 286 |
288 /// Report that metric [name] took [time] micro-seconds to process | 287 /// Report that metric [name] took [time] micro-seconds to process |
289 /// [inputSize] characters. | 288 /// [inputSize] characters. |
290 void report(String name, int time) { | 289 void report(String name, int time) { |
291 var sb = new StringBuffer(); | 290 var sb = new StringBuffer(); |
292 var padding = ' ' * (20 - name.length); | 291 var padding = ' ' * (20 - name.length); |
293 sb.write('$name:$padding $time us, ${time ~/ 1000} ms'); | 292 sb.write('$name:$padding $time us, ${time ~/ 1000} ms'); |
294 var invSpeed = (time * 1000 / inputSize).toStringAsFixed(2); | 293 var invSpeed = (time * 1000 / inputSize).toStringAsFixed(2); |
295 sb.write(', $invSpeed ns/char'); | 294 sb.write(', $invSpeed ns/char'); |
296 print('$sb'); | 295 print('$sb'); |
297 } | 296 } |
OLD | NEW |