import org.jdom.*; import org.jdom.input.*; import java.io.*; import java.util.*; public class test { public static byte[] fillByteArray( File file, SAXBuilder saxb ) throws IOException, JDOMException { int fileLength = (int)file.length(); System.out.println( "Reading file = " + file.getName() ); System.out.println( " size = " + fileLength ); byte[] ba = new byte[fileLength]; FileInputStream is = new FileInputStream( file ); is.read( ba, 0, fileLength ); ByteArrayInputStream bais = new ByteArrayInputStream( ba ); Document doc = saxb.build( bais ); return ba; } public static void performTest( boolean performTests, byte[] ba, SAXBuilder saxb ) throws JDOMException { Element.performAncestryTests( performTests ); System.out.println( "Performing ancestry testing: " + ( Element.isTestingAncestry() ? "ON" : "OFF" ) ); // Build the Document 10 times // and determine how much time it took. Date startTime = new Date(); for ( int j = 0; j<10; j++ ) { System.out.print( "Iteration[" + j + "] time: " ); Date iterStart = new Date(); ByteArrayInputStream bais = new ByteArrayInputStream( ba ); Document doc = saxb.build( bais ); bais = null; Date iterEnd = new Date(); long iterDiff = iterEnd.getTime() - iterStart.getTime(); System.out.println( iterDiff + " milliseconds" ); } Date endTime = new Date(); // Display the amount of time it took. long timeDiff = endTime.getTime() - startTime.getTime(); System.out.println( "Time: " + timeDiff + " milliseconds" ); } public static void main(String[] args) { try { String testFile = args.length == 1 ? args[0] : "test.xml"; // Initialize everything and prime it once. SAXBuilder saxb = new SAXBuilder(); File file = new File( testFile ); byte[] ba = fillByteArray( file, saxb ); performTest( true, ba, saxb ); performTest( false, ba, saxb ); } catch( Exception e ) { e.printStackTrace(); } } }