| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 #library('scanner_bench'); | 5 #library('scanner_bench'); |
| 6 #import('scannerlib.dart'); | 6 #import('scannerlib.dart'); |
| 7 #import('scanner_implementation.dart'); | 7 #import('scanner_implementation.dart'); |
| 8 #source('source_list.dart'); | 8 #source('source_list.dart'); |
| 9 | 9 |
| 10 /** | 10 /** |
| 11 * A common superclass for scanner benchmarks. | 11 * A common superclass for scanner benchmarks. |
| 12 */ | 12 */ |
| 13 class ScannerBench { | 13 class ScannerBench { |
| 14 void main(List<String> arguments) { | 14 void main(List<String> arguments) { |
| 15 for (String argument in arguments) { | 15 for (String argument in arguments) { |
| 16 checkExistence(argument); | 16 checkExistence(argument); |
| 17 } | 17 } |
| 18 tokenizeAll(print, 10, arguments); | 18 tokenizeAll(print, 10, arguments); |
| 19 tokenizeAll((x) {}, 1000, arguments); | 19 tokenizeAll((x) {}, 1000, arguments); |
| 20 tokenizeAll(print, 10, arguments); | 20 tokenizeAll(print, 10, arguments); |
| 21 } | 21 } |
| 22 | 22 |
| 23 void tokenizeAll(void log(String s), int iterations, List<String> arguments) { | 23 void tokenizeAll(void log(String s), int iterations, List<String> arguments) { |
| 24 ProgressBar bar = new ProgressBar(iterations); | 24 ProgressBar bar = new ProgressBar(iterations); |
| 25 bar.begin(); | 25 bar.begin(); |
| 26 for (int i = 0; i < iterations; i++) { | 26 for (int i = 0; i < iterations; i++) { |
| 27 bar.tick(); | 27 bar.tick(); |
| 28 StopWatch timer = new StopWatch(); | 28 Stopwatch timer = new Stopwatch(); |
| 29 timer.start(); | 29 timer.start(); |
| 30 int charCount = 0; | 30 int charCount = 0; |
| 31 for (final String argument in arguments) { | 31 for (final String argument in arguments) { |
| 32 charCount += tokenizeOne(argument); | 32 charCount += tokenizeOne(argument); |
| 33 } | 33 } |
| 34 timer.stop(); | 34 timer.stop(); |
| 35 log("Tokenized ${arguments.length} files (total size = ${charCount}) " + | 35 log("Tokenized ${arguments.length} files (total size = ${charCount}) " + |
| 36 "in ${timer.elapsedInMs()}ms (bytes)"); | 36 "in ${timer.elapsedInMs()}ms (bytes)"); |
| 37 } | 37 } |
| 38 bar.end(); | 38 bar.end(); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 } | 94 } |
| 95 ++ticks; | 95 ++ticks; |
| 96 } | 96 } |
| 97 | 97 |
| 98 void end() { | 98 void end() { |
| 99 if (total > 10) { | 99 if (total > 10) { |
| 100 print("$up$clear[$hashes] 100%"); | 100 print("$up$clear[$hashes] 100%"); |
| 101 } | 101 } |
| 102 } | 102 } |
| 103 } | 103 } |
| OLD | NEW |