package org.jdom.test.cases; /** * Insert the type's description here. * Creation date: (7/10/00 9:11:46 AM) * @author: */ import org.jdom.*; import org.jdom.input.SAXBuilder; import java.util.*; import java.io.*; public class TestCase_Performance { static Document doc = null; static Element form = null; static String xmldoc = "
\n" + "" + "somedata" + "" + "some more data\n" + "\n
"; private static final String DEFAULT_SAX_DRIVER_CLASS = "org.apache.xerces.parsers.SAXParser"; private static String saxDriverClass; private static SAXBuilder builder; /** * Creation date: (7/10/00 9:30:13 AM) * @param args java.lang.String[] */ public static void main(String[] args) { //junit.textui.TestRunner.run(suite()); setUp(); testMethod_NoException(); testMethod_WithException(); System.out.println("In reverse order...."); testMethod_WithException(); testMethod_NoException(); System.out.println("In reverse order again...."); testMethod_NoException(); testMethod_WithException(); } /** * Insert the method's description here. * Creation date: (7/10/00 9:18:54 AM) */ public static void setUp() { ByteArrayInputStream in = new ByteArrayInputStream(xmldoc.getBytes()); builder = new SAXBuilder(DEFAULT_SAX_DRIVER_CLASS); try { doc = builder.build(in); form = doc.getRootElement(); } catch (JDOMException e) { } } /** * Insert the method's description here. * Creation date: (7/10/00 9:13:45 AM) */ public static void testMethod_NoException() { long startTime = System.currentTimeMillis(); for (long i = 0; i < 1000000; i++) { Element test = form.getOptionalChild("field"); } long endTime = System.currentTimeMillis(); long elapsedTime = endTime - startTime; System.out.println("Time (ms) without exception: " + elapsedTime); } /** * Insert the method's description here. * Creation date: (7/10/00 9:13:45 AM) */ public static void testMethod_WithException() { long startTime = System.currentTimeMillis(); for (long i = 0; i < 1000000; i++) { try { Element test = form.getChild("field"); } catch (JDOMException e) { // } } long endTime = System.currentTimeMillis(); long elapsedTime = endTime - startTime; System.out.println("Time (ms) with exception: " + elapsedTime); } }