| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 #import('../lang.dart'); | |
| 6 | |
| 7 // TODO(jimhug): Turn this into proper benchmark! | |
| 8 | |
| 9 // TODO(jimhug): This is BROKEN with the move to experimental - will fix. | |
| 10 | |
| 11 /** Path to starting library or application. */ | |
| 12 final String ROOT = '../samples/swarm/swarm.dart'; | |
| 13 | |
| 14 /** Path to core library. */ | |
| 15 final String CORE = 'lib/corelib.dart'; | |
| 16 | |
| 17 void main() { | |
| 18 var t0 = Clock.now(); | |
| 19 initializeWorld(CORE); | |
| 20 world.getOrAddLibrary(ROOT); | |
| 21 world.process(); | |
| 22 var t1 = Clock.now(); | |
| 23 print ('first pass in ${(t1 - t0) / Clock.frequency()}secs'); | |
| 24 | |
| 25 testTokenize(world.sourcefiles); | |
| 26 testParse(world.sourcefiles, true); | |
| 27 testParse(world.sourcefiles, false); | |
| 28 | |
| 29 world.resolveAll(); | |
| 30 } | |
| 31 | |
| 32 void testTokenize(List<String> files) { | |
| 33 int count = 0; | |
| 34 final t0 = Clock.now(); | |
| 35 | |
| 36 for (var source in files) { | |
| 37 final tokenizer = new Tokenizer(source, true); | |
| 38 | |
| 39 while (true) { | |
| 40 final tok = tokenizer.next(); | |
| 41 if (tok.kind == TokenKind.ERROR) { | |
| 42 print(source.getLocationMessage('error ${tok}', tok.start, tok.end)); | |
| 43 } | |
| 44 count += 1; | |
| 45 if (tok.kind == TokenKind.END_OF_FILE) break; | |
| 46 } | |
| 47 } | |
| 48 | |
| 49 final t1 = Clock.now(); | |
| 50 final totalTime = (t1 - t0) / Clock.frequency(); | |
| 51 final tps = count / totalTime; | |
| 52 print('$count tokens in $totalTime secs, $tps tokens/sec'); | |
| 53 } | |
| 54 | |
| 55 void testParse(List<String> files, [bool diet=false]) { | |
| 56 int lines = 0; | |
| 57 | |
| 58 final t0 = Clock.now(); | |
| 59 | |
| 60 for (var source in files) { | |
| 61 final t00 = Clock.now(); | |
| 62 var p = new Parser(source, diet); | |
| 63 var decl = p.compilationUnit(); | |
| 64 var lines0 = lines; | |
| 65 lines += 1; | |
| 66 var code = source.text; | |
| 67 for (int i = 0; i < code.length; i++) { | |
| 68 if (code.charCodeAt(i) == 10/*newline*/) lines++; | |
| 69 } | |
| 70 final t11 = Clock.now(); | |
| 71 final totalTime = (t11 - t00) / Clock.frequency(); | |
| 72 final lps = (lines - lines0) / totalTime; | |
| 73 if (totalTime > 0.1) { | |
| 74 print('${source.filename} parsed in ${totalTime}sec, $lps lines/sec'); | |
| 75 } | |
| 76 } | |
| 77 | |
| 78 final t1 = Clock.now(); | |
| 79 final totalTime = (t1 - t0) / Clock.frequency(); | |
| 80 final lps = lines/totalTime; | |
| 81 print('${diet ? "diet " : ""}parsed $lines lines in $totalTime sec, $lps lines
/sec'); | |
| 82 } | |
| OLD | NEW |