diff -ruN xmlbench/build.xml xmlbench-p1/build.xml --- xmlbench/build.xml Mon Jul 2 16:08:01 2001 +++ xmlbench-p1/build.xml Mon Jul 2 16:42:14 2001 @@ -10,15 +10,14 @@ =================================================================== --> - + - - - - + + + @@ -36,6 +35,8 @@ + + @@ -82,7 +83,7 @@ - + diff -ruN xmlbench/src/com/sosnoski/xmlbench/BenchDOM.java xmlbench-p1/src/com/sosnoski/xmlbench/BenchDOM.java --- xmlbench/src/com/sosnoski/xmlbench/BenchDOM.java Mon Jul 2 16:08:01 2001 +++ xmlbench-p1/src/com/sosnoski/xmlbench/BenchDOM.java Fri Jun 15 15:07:56 2001 @@ -32,9 +32,9 @@ * representations. Subclasses need to implement the actual document building * and text output methods, but can use the common tree walking code provided * here. - * - * @author Dennis M. Sosnoski - * @version 1.0 + * + * @author Dennis M. Sosnoski, Ryosuke Nanba + * @version 1.0pl1 */ public abstract class BenchDOM extends BenchDocBase @@ -58,8 +58,12 @@ */ protected void walkElement(Element element, DocumentSummary summary) { - if (element.hasAttributes()) { - summary.addAttributes(element.getAttributes().getLength()); + //if (element.hasAttributes()) { + // summary.addAttributes(element.getAttributes().getLength()); + //} + NamedNodeMap nm = element.getAttributes(); + if (nm != null) { + summary.addAttributes(nm.getLength()); } if (element.hasChildNodes()) { Node child = (Node)element.getFirstChild(); diff -ruN xmlbench/src/com/sosnoski/xmlbench/BenchDocBase.java xmlbench-p1/src/com/sosnoski/xmlbench/BenchDocBase.java --- xmlbench/src/com/sosnoski/xmlbench/BenchDocBase.java Mon Jul 2 16:08:01 2001 +++ xmlbench-p1/src/com/sosnoski/xmlbench/BenchDocBase.java Sun Jul 1 09:33:29 2001 @@ -32,8 +32,8 @@ * be defined by the subclass for each particular document representation to * be tested. * - * @author Dennis M. Sosnoski - * @version 1.0 + * @author Dennis M. Sosnoski, Ryosuke Nanba + * @version 1.0pl1 */ public abstract class BenchDocBase extends BenchBase @@ -205,10 +205,17 @@ public DocumentSummary runTest(int count, byte[] text, boolean print, boolean memory) { + if(XMLBench.warmup) { // warmup parser ...RNa. + Object[] docs = new Object[1]; + docs[0] = build(text); + walkAll(docs); + docs[0] = null; + docs = null; + } initPass(print, memory); DocumentSummary summary; byte[] out = null; - byte[] serial; + byte[] serial = null; if (memory) { Object[] docs = new Object[count]; for (int i = 0; i < count; i++) { @@ -218,55 +225,72 @@ initTime(); summary = walkAll(docs); reportSpaceTime("Walked tree", count); - initTime(); - for (int i = 0; i < count; i++) { - out = output(docs[i]); + if(XMLBench.output) { + initTime(); + for (int i = 0; i < count; i++) { + out = output(docs[i]); + } + reportTime("Generated text"); + initTime(); + serial = serializeAll(docs); } - reportTime("Generated text"); - initTime(); - serial = serializeAll(docs); } else { Object doc = null; for (int i = 0; i < count; i++) { doc = build(text); } reportTime("Built from parse"); + if(XMLBench.gcBeforeWalk) { + long done = System.currentTimeMillis() + + BenchBase.GARBAGE_COLLECT_DELAY; + Runtime rt = Runtime.getRuntime(); + while (System.currentTimeMillis() < done) { + rt.gc(); + try { + Thread.sleep(BenchBase.GARBAGE_COLLECT_DELAY); + } catch (InterruptedException ex) {} + } + } initTime(); summary = new DocumentSummary(); for (int i = 0; i < count; i++) { walk(doc, summary); } reportTime("Walked tree"); - initTime(); - for (int i = 0; i < count; i++) { - out = output(doc); - } - reportTime("Generated text"); - initTime(); - serial = serialize(doc); - if (serial != null) { - for (int i = 1; i < count; i++) { - serial = serialize(doc); + if(XMLBench.output) { + initTime(); + for (int i = 0; i < count; i++) { + out = output(doc); + } + reportTime("Generated text"); + initTime(); + serial = serialize(doc); + if (serial != null) { + for (int i = 1; i < count; i++) { + serial = serialize(doc); + } } } } - if (serial == null) { - if (print) { - System.out.println(" **Serialization not supported**"); - } - } else { - reportTime("Serialized"); - initTime(); - Object restored = null; - for (int i = 0; i < count; i++) { - restored = unserialize(serial); - } - reportTime("Unserialized"); - if (print) { - byte[] bytes = output(restored); - if (!Arrays.equals(bytes, out)) { - System.out.println(" **Output text from " + + if(XMLBench.output) { + if (serial == null) { + if (print) { + System.out.println(" **Serialization not supported**"); + } + } else { + reportTime("Serialized"); + initTime(); + Object restored = null; + for (int i = 0; i < count; i++) { + restored = unserialize(serial); + } + reportTime("Unserialized"); + if (print) { + byte[] bytes = output(restored); + if (!Arrays.equals(bytes, out)) { + System.out.println(" **Output text from " + "unserialized document does not match**"); + } } } } @@ -276,7 +300,8 @@ " attributes, and " + summary.getTextCharCount() + " characters of text"); System.out.println(" Original text size was " + text.length + - ", output text size was " + out.length); + (XMLBench.output ? + ", output text size was " + out.length : "")); if (serial != null) { System.out.println(" Serialized length was " + serial.length); } diff -ruN xmlbench/src/com/sosnoski/xmlbench/BenchElectric.java xmlbench-p1/src/com/sosnoski/xmlbench/BenchElectric.java --- xmlbench/src/com/sosnoski/xmlbench/BenchElectric.java Mon Jul 2 16:08:01 2001 +++ xmlbench-p1/src/com/sosnoski/xmlbench/BenchElectric.java Sun Jul 1 11:30:19 2001 @@ -26,6 +26,7 @@ import java.util.*; import electric.xml.*; +import electric.util.*; /** * Benchmark for measuring performance of the Electric XML document diff -ruN xmlbench/src/com/sosnoski/xmlbench/BenchIPEX.java xmlbench-p1/src/com/sosnoski/xmlbench/BenchIPEX.java --- xmlbench/src/com/sosnoski/xmlbench/BenchIPEX.java Thu Jan 1 09:00:00 1970 +++ xmlbench-p1/src/com/sosnoski/xmlbench/BenchIPEX.java Wed Jun 6 21:46:27 2001 @@ -0,0 +1,118 @@ +/* + * Copyright (c) 2000-2001 Sosnoski Software Solutions, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +package com.sosnoski.xmlbench; + +import java.io.*; +import java.util.*; + +import org.w3c.dom.*; + +import com.infoteria.ipex.dom.*; +import com.infoteria.ipex.stream.*; + +/** + * Benchmark for measuring performance of the Apache Crimson DOM document + * representation. + * + * @author Ryosuke Nanba + * @version 1.0 + */ + +public class BenchIPEX extends BenchDOM +{ + /** Document builder used within a test run. */ + private com.infoteria.ipex.dom.Reader m_builder; + + /** + * Constructor. + */ + + public BenchIPEX() { + super("iPEX4J DOM"); + } + + /** + * Build document representation by parsing XML. This implementation + * creates a document builder if one does not already exist, then reuses + * that builder for the duration of a test run.. + * + * @param text XML document text + * @return document representation + */ + + protected Object build(byte[] text) { + if (m_builder == null) { + try { + int flag = com.infoteria.ipex.dom.Reader.LOAD_EXTERNAL_GE; + m_builder = + new com.infoteria.ipex.dom.XMLReader(null, flag, null); + // ? ...setNamespaceAware(true); + } catch (Exception ex) { + ex.printStackTrace(System.err); + System.exit(0); + } + } + Object doc = null; + try { + com.infoteria.ipex.stream.InputStream instream = + new com.infoteria.ipex.stream.InputStreamByByte(text); + m_builder.setStream(instream); + doc = m_builder.read(); + } catch (Exception ex) { + ex.printStackTrace(System.err); + System.exit(0); + } + return doc; + } + + /** + * Output a document as XML text. This method uses the method defined + * by the Crimson DOM to output a text representation of the document. + * + * @param doc document representation to be output + * @return generated text representation + */ + + protected byte[] output(Object doc) { + com.infoteria.ipex.stream.OutputStreamByByte out; + out = new com.infoteria.ipex.stream.OutputStreamByByte(); + com.infoteria.ipex.dom.Writer writer = + new com.infoteria.ipex.dom.XMLWriter(out,"utf-8"); + try { + writer.write((Document)doc, true); + } catch (Exception ex) { + ex.printStackTrace(System.err); + System.exit(0); + } + return out.getBuffer(); + } + + /** + * Reset test class instance. This discards the document builder used + * within a test pass. + */ + + protected void reset() { + m_builder = null; + } +} diff -ruN xmlbench/src/com/sosnoski/xmlbench/BenchOracle.java xmlbench-p1/src/com/sosnoski/xmlbench/BenchOracle.java --- xmlbench/src/com/sosnoski/xmlbench/BenchOracle.java Thu Jan 1 09:00:00 1970 +++ xmlbench-p1/src/com/sosnoski/xmlbench/BenchOracle.java Tue Jun 26 08:52:51 2001 @@ -0,0 +1,81 @@ +package com.sosnoski.xmlbench; + +import java.io.*; +import java.util.*; + +import oracle.xml.parser.v2.*; +import org.w3c.dom.*; +/** + * Benchmark for measuring performance of the Oracle XML Parser v2 + * representation. + * + * @author Ryosuke Nanba + * @version 1.0 + */ +public class BenchOracle extends BenchDOM +{ + /** Document builder used within a test run. */ + private oracle.xml.parser.v2.DOMParser m_builder; + + /** + * Constructor. + */ + + public BenchOracle() { + super("Oracle DOM"); + } + + /** + * Build document representation by parsing XML. This implementation + * creates a document builder if one does not already exist, then reuses + * that builder for the duration of a test run.. + * + * @param text XML document text + * @return document representation + */ + + protected Object build(byte[] text) { + if (m_builder == null) { + try { + m_builder = new oracle.xml.parser.v2.DOMParser(); + m_builder.setValidationMode(false); + } catch (Exception ex) { + ex.printStackTrace(System.err); + System.exit(0); + } + } + Object doc = null; + try { + InputStream is = new ByteArrayInputStream(text); + m_builder.parse(is); + doc = m_builder.getDocument(); + m_builder.reset(); + } catch (Exception ex) { + ex.printStackTrace(System.err); + System.exit(0); + } + return doc; + } + + /** + * Output a document as XML text. This method uses the method defined + * by the Xerces DOM to output a text representation of the document. + * + * @param doc document representation to be output + * @return generated text representation + */ + + protected byte[] output(Object doc) { + ByteArrayOutputStream out = new ByteArrayOutputStream(); + try { + ((oracle.xml.parser.v2.XMLDocument)doc).print(out); + } catch (Exception ex) { + ex.printStackTrace(System.err); + System.exit(0); + } + return out.toByteArray(); + } + protected void reset() { + m_builder = null; + } +} diff -ruN xmlbench/src/com/sosnoski/xmlbench/XMLBench.java xmlbench-p1/src/com/sosnoski/xmlbench/XMLBench.java --- xmlbench/src/com/sosnoski/xmlbench/XMLBench.java Mon Jul 2 16:08:01 2001 +++ xmlbench-p1/src/com/sosnoski/xmlbench/XMLBench.java Mon Jul 2 16:08:36 2001 @@ -36,25 +36,30 @@ * speed and memory requirement for constructing the document representation * from a SAX parse, and in terms of speed for walking the representation and * generating text output. - * - * @author Dennis M. Sosnoski - * @version 1.0 + * + * @author Dennis M. Sosnoski, Ryosuke Nanba + * @version 1.0p1 */ public class XMLBench { /** Interval in milliseconds to wait between test passes. */ public static final long DELAY_BETWEEN_TESTS = 1000; - + public static boolean warmup = false; + public static boolean output = false; + public static boolean gcBeforeWalk = false; + /** Set of tests to run. */ private static final BenchBase[] s_testSet = { new BenchSAX(), + new BenchIPEX(), new BenchCrimson(), - new BenchJDOM(), - new BenchDOM4J(), + new BenchOracle(), + //new BenchJDOM(), + //new BenchDOM4J(), new BenchXercesBase(), - new BenchXercesDeferred(), - new BenchElectric() + //new BenchXercesDeferred(), + //new BenchElectric() }; /** @@ -121,6 +126,12 @@ index = Integer.parseInt(argv[++i]); } else if ("-space".equals(argv[i])) { memory = true; + } else if ("-output".equals(argv[i])) { + output = true; + } else if ("-w".equals(argv[i])) { + warmup = true; + } else if ("-gbw".equals(argv[i])) { + gcBeforeWalk = true; } } @@ -165,9 +176,12 @@ "indexed by\n" + " the next parameter value (range is 0 to " + (s_testSet.length-1) + ")\n" + - " [-space] - check memory space used by document models " + - "(may make\n" + - " timing tests less accurate)\n"); + " [-space] - check memory space used by document models\n" + + " (may make timing tests less accurate)\n" + + " [-output] - test writer and serializer/deserializer \n" + + " [-w] - warmup parser \n" + + " [-gbw] - invoke gc() before tree walk. \n" + ); } } }