| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | |
| 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. | |
| 4 | |
| 5 library dart_style.benchmark.benchmark; | |
| 6 | |
| 7 import 'dart:io'; | |
| 8 | |
| 9 import 'package:dart_style/dart_style.dart'; | |
| 10 | |
| 11 const NUM_TRIALS = 100; | |
| 12 const FORMATS_PER_TRIAL = 30; | |
| 13 | |
| 14 void main(List<String> args) { | |
| 15 var best = 99999999.0; | |
| 16 | |
| 17 // Run the benchmark several times. This ensures the VM is warmed up and lets | |
| 18 // us see how much variance there is. | |
| 19 for (var i = 0; i <= NUM_TRIALS; i++) { | |
| 20 var start = new DateTime.now(); | |
| 21 | |
| 22 // For a single benchmark, format the source multiple times. | |
| 23 for (var j = 0; j < FORMATS_PER_TRIAL; j++) { | |
| 24 formatSource(); | |
| 25 } | |
| 26 | |
| 27 var elapsed = new DateTime.now() | |
| 28 .difference(start).inMilliseconds / FORMATS_PER_TRIAL; | |
| 29 | |
| 30 // Keep track of the best run so far. | |
| 31 if (elapsed >= best) continue; | |
| 32 best = elapsed; | |
| 33 | |
| 34 // Don't print the first run. It's always terrible since the VM hasn't | |
| 35 // warmed up yet. | |
| 36 if (i == 0) continue; | |
| 37 printResult("Run ${padLeft('#$i', 3)}", elapsed); | |
| 38 } | |
| 39 | |
| 40 printResult("Best ", best); | |
| 41 } | |
| 42 | |
| 43 void printResult(String label, double time) { | |
| 44 print("$label: ${padLeft(time.toStringAsFixed(2), 4)}ms " | |
| 45 "${'=' * ((time * 5).toInt())}"); | |
| 46 } | |
| 47 | |
| 48 String padLeft(input, int length) { | |
| 49 var result = input.toString(); | |
| 50 if (result.length < length) { | |
| 51 result = " " * (length - result.length) + result; | |
| 52 } | |
| 53 | |
| 54 return result; | |
| 55 } | |
| 56 | |
| 57 void formatSource() { | |
| 58 var formatter = new DartFormatter(); | |
| 59 var result = formatter.format(source); | |
| 60 | |
| 61 // Sanity check to make sure the output is what we expect and to make sure | |
| 62 // the VM doesn't optimize "dead" code away. | |
| 63 if (result.length != 29791) { | |
| 64 print("Incorrect output (length ${result.length}):\n$result"); | |
| 65 exit(1); | |
| 66 } | |
| 67 } | |
| 68 | |
| 69 const source = r""" | |
| 70 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 71 // 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 |
| 72 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 73 | 4 |
| 74 library pub.solver.backtracking_solver; | 5 library pub.solver.backtracking_solver; |
| 75 | 6 |
| 76 import 'dart:async'; | 7 import 'dart:async'; |
| 77 import 'dart:collection' show Queue; | 8 import 'dart:collection' show Queue; |
| 78 | 9 |
| 79 import '../barback.dart' as barback; | 10 import '../barback.dart' as barback; |
| (...skipping 794 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 874 /// with the current SDK. | 805 /// with the current SDK. |
| 875 /// | 806 /// |
| 876 /// Throws a [SolveFailure] if not. | 807 /// Throws a [SolveFailure] if not. |
| 877 void _validateSdkConstraint(Pubspec pubspec) { | 808 void _validateSdkConstraint(Pubspec pubspec) { |
| 878 if (pubspec.environment.sdkVersion.allows(sdk.version)) return; | 809 if (pubspec.environment.sdkVersion.allows(sdk.version)) return; |
| 879 | 810 |
| 880 throw new BadSdkVersionException( | 811 throw new BadSdkVersionException( |
| 881 pubspec.name, | 812 pubspec.name, |
| 882 'Package ${pubspec.name} requires SDK version ' | 813 'Package ${pubspec.name} requires SDK version ' |
| 883 '${pubspec.environment.sdkVersion} but the current SDK is ' '${sdk.ver
sion}.'); | 814 '${pubspec.environment.sdkVersion} but the current SDK is ' '${sdk.ver
sion}.'); |
| 884 } | 815 } |
| 885 """; | |
| OLD | NEW |