i am testing efficiency of DOM, SAX and StAX.
Basically what i do is that i use spring stopwatch and different sizes of XML and then compare results.
I also thought that i could measure time while elements are loaded to objects and objects to array, but that has nothing to do with parsring.
here are my codes for SAX
StopWatch stopWatch = new StopWatch("SAX");
stopWatch.start("SAX");
SAXParserFactory spf = SAXParserFactory.newInstance();
spf.setValidating(false);
SAXParser sp = spf.newSAXParser();
XMLReader parser = sp.getXMLReader();
parser.setErrorHandler(new Chyby());
parser.setContentHandler(new DefaultHandler());
parser.parse(file);
stopWatch.stop();
System.out.println(stopWatch.prettyPrint());
for StAX
int temp = 0;
StopWatch stopWatch = new StopWatch("StAX");
stopWatch.start("StAX");
XMLInputFactory f = XMLInputFactory.newInstance();
XMLStreamReader r = f.createXMLStreamReader( new FileInputStream( file ));
while (r.hasNext()==true){
temp++;
r.next();
}
System.out.println("parsed");
stopWatch.stop();
System.out.println(stopWatch.prettyPrint());
DOM
StopWatch stopWatch = new StopWatch("DOM");
stopWatch.start("DOM");
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.parse(subor);
System.out.println("parsed");
System.out.println("----------------\n");
stopWatch.stop();
System.out.println(stopWatch.prettyPrint());
My question is: Am i doing it right? is there other approach for testing parsers? Thanks