OLD | NEW |
1 package com.google.dart.tools.core.analysis.timing; | 1 package com.google.dart.tools.core.analysis.timing; |
2 | 2 |
| 3 import com.google.dart.engine.error.GatheringErrorListener; |
3 import com.google.dart.engine.html.parser.HtmlParseResult; | 4 import com.google.dart.engine.html.parser.HtmlParseResult; |
4 import com.google.dart.engine.html.parser.HtmlParser; | 5 import com.google.dart.engine.html.parser.HtmlParser; |
5 import com.google.dart.engine.source.FileBasedSource; | 6 import com.google.dart.engine.source.FileBasedSource; |
6 import com.google.dart.engine.source.Source; | 7 import com.google.dart.engine.source.Source; |
7 import com.google.dart.engine.source.SourceFactory; | 8 import com.google.dart.engine.source.SourceFactory; |
8 import com.google.dart.engine.utilities.io.FileUtilities; | 9 import com.google.dart.engine.utilities.io.FileUtilities; |
9 | 10 |
10 import junit.framework.TestCase; | 11 import junit.framework.TestCase; |
11 | 12 |
12 import java.io.File; | 13 import java.io.File; |
13 import java.io.IOException; | 14 import java.io.IOException; |
14 | 15 |
15 /** | 16 /** |
16 * Evaluate time to parse html files in a directory hierarchy using old and new
HtmlParsers. | 17 * Evaluate time to parse html files in a directory hierarchy using old and new
HtmlParsers. |
17 */ | 18 */ |
18 public class HtmlParserTimings extends TestCase { | 19 public class HtmlParserTimings extends TestCase { |
19 interface ParseFileRunner { | 20 interface ParseFileRunner { |
20 void run(File htmlFile) throws Exception; | 21 void run(File htmlFile) throws Exception; |
21 } | 22 } |
22 interface ParseStringRunner { | 23 interface ParseStringRunner { |
23 void run(File htmlFile, String contents) throws Exception; | 24 void run(File htmlFile, String contents) throws Exception; |
24 } | 25 } |
25 | 26 |
26 final ParseFileRunner newParseFile = new ParseFileRunner() { | 27 final ParseFileRunner newParseFile = new ParseFileRunner() { |
27 private SourceFactory sourceFactory = new SourceFactory(); | 28 private SourceFactory sourceFactory = new SourceFactory(); |
28 | 29 |
29 @Override | 30 @Override |
30 public void run(File htmlFile) throws Exception { | 31 public void run(File htmlFile) throws Exception { |
31 Source source = new FileBasedSource(sourceFactory.getContentCache(), htmlF
ile); | 32 Source source = new FileBasedSource(sourceFactory.getContentCache(), htmlF
ile); |
32 HtmlParseResult parseResult = new HtmlParser(source).parse(source); | 33 GatheringErrorListener errorListener = new GatheringErrorListener(); |
| 34 HtmlParseResult parseResult = new HtmlParser(source, errorListener).parse(
source); |
33 assertNotNull(parseResult); | 35 assertNotNull(parseResult); |
34 } | 36 } |
35 }; | 37 }; |
36 | 38 |
37 final ParseStringRunner newParseString = new ParseStringRunner() { | 39 final ParseStringRunner newParseString = new ParseStringRunner() { |
38 private SourceFactory sourceFactory = new SourceFactory(); | 40 private SourceFactory sourceFactory = new SourceFactory(); |
39 | 41 |
40 @Override | 42 @Override |
41 public void run(File htmlFile, String contents) throws Exception { | 43 public void run(File htmlFile, String contents) throws Exception { |
42 Source source = new FileBasedSource(sourceFactory.getContentCache(), htmlF
ile); | 44 Source source = new FileBasedSource(sourceFactory.getContentCache(), htmlF
ile); |
43 sourceFactory.setContents(source, contents); | 45 sourceFactory.setContents(source, contents); |
44 HtmlParseResult parseResult = new HtmlParser(source).parse(source); | 46 GatheringErrorListener errorListener = new GatheringErrorListener(); |
| 47 HtmlParseResult parseResult = new HtmlParser(source, errorListener).parse(
source); |
45 assertNotNull(parseResult); | 48 assertNotNull(parseResult); |
46 } | 49 } |
47 }; | 50 }; |
48 | 51 |
49 final ParseFileRunner oldParseFile = new ParseFileRunner() { | 52 final ParseFileRunner oldParseFile = new ParseFileRunner() { |
50 @Override | 53 @Override |
51 public void run(File htmlFile) throws IOException { | 54 public void run(File htmlFile) throws IOException { |
52 String contents = FileUtilities.getContents(htmlFile); | 55 String contents = FileUtilities.getContents(htmlFile); |
53 Object parseResult = new com.google.dart.tools.core.html.HtmlParser(conten
ts).parse(); | 56 Object parseResult = new com.google.dart.tools.core.html.HtmlParser(conten
ts).parse(); |
54 assertNotNull(parseResult); | 57 assertNotNull(parseResult); |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 } else if (file.getName().endsWith(".html")) { | 147 } else if (file.getName().endsWith(".html")) { |
145 String contents = FileUtilities.getContents(file); | 148 String contents = FileUtilities.getContents(file); |
146 long start = System.currentTimeMillis(); | 149 long start = System.currentTimeMillis(); |
147 runner.run(file, contents); | 150 runner.run(file, contents); |
148 parseTime += System.currentTimeMillis() - start; | 151 parseTime += System.currentTimeMillis() - start; |
149 fileCount++; | 152 fileCount++; |
150 } | 153 } |
151 } | 154 } |
152 } | 155 } |
153 } | 156 } |
OLD | NEW |