/* * JDOMTimeTest.java * * Created 2000 by Petri Wessman * * @(#)$Id: JDOMParse.java,v 1.1 2000/07/05 08:24:13 orava Exp $ * */ package orava.test; import java.io.*; import org.jdom.*; import org.jdom.input.SAXBuilder; /** * * @author Petri Wessman * @version $Revision: 1.1 $ */ public class JDOMTimeTest { public static final long ITER = 1000000; private static final String SAX_DRIVER = "org.apache.xerces.parsers.SAXParser"; private SAXBuilder builder; public JDOMTimeTest () { builder = new SAXBuilder(SAX_DRIVER,true); } public void runtest (String filename) throws IOException, JDOMException { Document doc = builder.build(new File(filename)); System.out.println("XML parsed"); Element sitemap = doc.getRootElement(); Element node = sitemap.getChild("node"); System.out.println("Doing JDOM method call version"); long start = System.currentTimeMillis(); for (long i = 0; i < ITER; ++i) { Attribute attr = null; try { attr = node.getAttribute("foo",""); } catch (NoSuchAttributeException e) { // } if (attr != null) { throw new JDOMException("attr foo found!?!"); } } long delta = (System.currentTimeMillis() - start) / 1000; System.out.println("done, duration: " + delta + "s\n"); System.out.println("Doing hacked JDOM method call version"); start = System.currentTimeMillis(); for (long i = 0; i < ITER; ++i) { Attribute attr = node.getAttributeHacked("foo",""); if (attr != null) { throw new JDOMException("attr foo found!?!"); } } delta = (System.currentTimeMillis() - start) / 1000; System.out.println("done, duration: " + delta + "s\n"); } public static void main(String[] args) { try { JDOMTimeTest test = new JDOMTimeTest(); test.runtest("sitemap.xml"); } catch (JDOMException e) { System.err.println("JDOM ERROR: " + e.toString()); } catch (Exception e) { System.err.println("EXCEPTION: " + e.toString()); } } } /* * Local Variables: * make-backup-files: t * End: */