| 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:analyzer/src/fasta/ast_builder.dart'; | 11 import 'package:analyzer/src/fasta/ast_builder.dart'; |
| 12 import 'package:front_end/front_end.dart'; | 12 import 'package:front_end/front_end.dart'; |
| 13 import 'package:front_end/src/base/processed_options.dart'; | 13 import 'package:front_end/physical_file_system.dart'; |
| 14 import 'package:front_end/src/fasta/parser.dart'; | 14 import 'package:front_end/src/fasta/parser.dart'; |
| 15 import 'package:front_end/src/fasta/scanner.dart'; | 15 import 'package:front_end/src/fasta/scanner.dart'; |
| 16 import 'package:front_end/src/fasta/scanner/io.dart' show readBytesFromFileSync; | 16 import 'package:front_end/src/fasta/scanner/io.dart' show readBytesFromFileSync; |
| 17 import 'package:front_end/src/fasta/source/directive_listener.dart'; | 17 import 'package:front_end/src/fasta/source/directive_listener.dart'; |
| 18 import 'package:front_end/src/fasta/uri_translator.dart' show UriTranslator; | 18 import 'package:front_end/src/fasta/uri_translator.dart' show UriTranslator; |
| 19 import 'package:front_end/src/fasta/parser/native_support.dart' | 19 import 'package:front_end/src/fasta/parser/native_support.dart' |
| 20 show skipNativeClause; | 20 show skipNativeClause; |
| 21 import 'package:front_end/src/fasta/uri_translator_impl.dart'; |
| 21 | 22 |
| 22 /// Cumulative total number of chars scanned. | 23 /// Cumulative total number of chars scanned. |
| 23 int inputSize = 0; | 24 int inputSize = 0; |
| 24 | 25 |
| 25 /// Cumulative time spent scanning. | 26 /// Cumulative time spent scanning. |
| 26 Stopwatch scanTimer = new Stopwatch(); | 27 Stopwatch scanTimer = new Stopwatch(); |
| 27 | 28 |
| 28 main(List<String> args) async { | 29 main(List<String> args) async { |
| 29 // TODO(sigmund): provide sdk folder as well. | 30 // TODO(sigmund): provide sdk folder as well. |
| 30 if (args.length < 2) { | 31 if (args.length < 2) { |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 // sdk directly. | 73 // sdk directly. |
| 73 Uri sdkRoot = | 74 Uri sdkRoot = |
| 74 Uri.base.resolve(Platform.resolvedExecutable).resolve('patched_sdk/'); | 75 Uri.base.resolve(Platform.resolvedExecutable).resolve('patched_sdk/'); |
| 75 | 76 |
| 76 /// Translates `dart:*` and `package:*` URIs to resolved URIs. | 77 /// Translates `dart:*` and `package:*` URIs to resolved URIs. |
| 77 UriTranslator uriResolver; | 78 UriTranslator uriResolver; |
| 78 | 79 |
| 79 /// Preliminary set up to be able to correctly resolve URIs on the given | 80 /// Preliminary set up to be able to correctly resolve URIs on the given |
| 80 /// program. | 81 /// program. |
| 81 Future setup(Uri entryUri) async { | 82 Future setup(Uri entryUri) async { |
| 82 var options = new CompilerOptions() | 83 uriResolver = |
| 83 ..sdkRoot = sdkRoot | 84 await UriTranslatorImpl.parse(PhysicalFileSystem.instance, sdkRoot); |
| 84 ..compileSdk = true | |
| 85 ..packagesFileUri = Uri.base.resolve('.packages'); | |
| 86 uriResolver = await new ProcessedOptions(options).getUriTranslator(); | |
| 87 } | 85 } |
| 88 | 86 |
| 89 /// Scan [contents] and return the first token produced by the scanner. | 87 /// Scan [contents] and return the first token produced by the scanner. |
| 90 Token tokenize(List<int> contents) { | 88 Token tokenize(List<int> contents) { |
| 91 scanTimer.start(); | 89 scanTimer.start(); |
| 92 var token = scan(contents).tokens; | 90 var token = scan(contents).tokens; |
| 93 scanTimer.stop(); | 91 scanTimer.stop(); |
| 94 return token; | 92 return token; |
| 95 } | 93 } |
| 96 | 94 |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 /// Report that metric [name] took [time] micro-seconds to process | 245 /// Report that metric [name] took [time] micro-seconds to process |
| 248 /// [inputSize] characters. | 246 /// [inputSize] characters. |
| 249 void report(String name, int time) { | 247 void report(String name, int time) { |
| 250 var sb = new StringBuffer(); | 248 var sb = new StringBuffer(); |
| 251 var padding = ' ' * (20 - name.length); | 249 var padding = ' ' * (20 - name.length); |
| 252 sb.write('$name:$padding $time us, ${time ~/ 1000} ms'); | 250 sb.write('$name:$padding $time us, ${time ~/ 1000} ms'); |
| 253 var invSpeed = (time * 1000 / inputSize).toStringAsFixed(2); | 251 var invSpeed = (time * 1000 / inputSize).toStringAsFixed(2); |
| 254 sb.write(', $invSpeed ns/char'); | 252 sb.write(', $invSpeed ns/char'); |
| 255 print('$sb'); | 253 print('$sb'); |
| 256 } | 254 } |
| OLD | NEW |