You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by di...@apache.org on 2006/03/31 21:59:17 UTC
svn commit: r390489 [4/4] - in
/webservices/axis2/trunk/archive/java/scratch/dennis: ./ bin/ docs/
docs/soaps/ lib/ src/ src/com/ src/com/sosnoski/ src/com/sosnoski/args/
src/com/sosnoski/xmlbench/ src/com/sosnoski/xmlbench/models/
Added: webservices/axis2/trunk/archive/java/scratch/dennis/src/com/sosnoski/xmlbench/models/BenchDOM.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/archive/java/scratch/dennis/src/com/sosnoski/xmlbench/models/BenchDOM.java?rev=390489&view=auto
==============================================================================
--- webservices/axis2/trunk/archive/java/scratch/dennis/src/com/sosnoski/xmlbench/models/BenchDOM.java (added)
+++ webservices/axis2/trunk/archive/java/scratch/dennis/src/com/sosnoski/xmlbench/models/BenchDOM.java Fri Mar 31 11:59:03 2006
@@ -0,0 +1,197 @@
+/*
+ * 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.models;
+
+import java.io.*;
+import java.util.*;
+
+import org.w3c.dom.*;
+
+import com.sosnoski.xmlbench.DocumentSummary;
+
+/**
+ * Abstract base class for measuring performance of any of the DOM document
+ * 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.1
+ */
+
+public abstract class BenchDOM extends BenchDocBase
+{
+ /**
+ * Constructor.
+ *
+ * @param config test configuration name
+ */
+
+ protected BenchDOM(String config) {
+ super(config);
+ }
+
+ /**
+ * Walk subtree for element. This recursively walks through the document
+ * nodes under an element, accumulating summary information.
+ *
+ * @param element element to be walked
+ * @param summary document summary information
+ */
+
+ protected void walkElement(Element element, DocumentSummary summary) {
+
+ // include attribute values in summary
+ if (element.hasAttributes()) {
+ NamedNodeMap attrs = element.getAttributes();
+ for (int i = 0; i < attrs.getLength(); i++) {
+ summary.addAttribute(attrs.item(i).getNodeValue().length());
+ }
+ }
+
+ // loop through children
+ if (element.hasChildNodes()) {
+ Node child = (Node)element.getFirstChild();
+ while (child != null) {
+
+ // handle child by type
+ int type = child.getNodeType();
+ if (type == Node.TEXT_NODE) {
+ summary.addContent(child.getNodeValue().length());
+ } else if (type == Node.ELEMENT_NODE) {
+ summary.addElements(1);
+ walkElement((Element)child, summary);
+ }
+ child = child.getNextSibling();
+ }
+ }
+ }
+
+ /**
+ * Walk and summarize document. This method walks through the nodes
+ * of the document, accumulating summary information.
+ *
+ * @param doc document representation to be walked
+ * @param summary output document summary information
+ */
+
+ protected void walk(Object doc, DocumentSummary summary) {
+ summary.addElements(1);
+ walkElement(((Document)doc).getDocumentElement(), summary);
+ }
+
+ /**
+ * Modify subtree for element. This recursively walks through the document
+ * nodes under an element, performing the modifications.
+ *
+ * @param element element to be walked
+ */
+
+ protected void modifyElement(Element element) {
+
+ // check for children present
+ if (element.hasChildNodes()) {
+
+ // loop through child nodes
+ Node child;
+ Node next = (Node)element.getFirstChild();
+ Document doc = null;
+ String prefix = null;
+ String uri = null;
+ boolean content = false;
+ while ((child = next) != null) {
+
+ // set next before we change anything
+ next = child.getNextSibling();
+
+ // handle child by node type
+ if (child.getNodeType() == Node.TEXT_NODE) {
+
+ // trim whitespace from content text
+ String trimmed = child.getNodeValue().trim();
+ if (trimmed.length() == 0) {
+
+ // delete child if nothing but whitespace
+ element.removeChild(child);
+
+ } else {
+
+ // make sure we have the parent element information
+ if (!content) {
+ doc = element.getOwnerDocument();
+ prefix = element.getPrefix();
+ uri = element.getNamespaceURI();
+ content = true;
+ }
+
+ // create a "text" element matching parent namespace
+ Element text;
+ if (uri == null) {
+ text = doc.createElement("text");
+ } else {
+ text = doc.createElementNS(uri, prefix + ":text");
+ }
+
+ // wrap the trimmed content with new element
+ text.appendChild(doc.createTextNode(trimmed));
+ element.replaceChild(text, child);
+
+ }
+ } else if (child.getNodeType() == Node.ELEMENT_NODE) {
+
+ // handle child elements with recursive call
+ modifyElement((Element)child);
+
+ }
+ }
+
+ // check if we've seen any non-whitespace content for element
+ if (content) {
+
+ // add attribute flagging content found
+ if (prefix == null || prefix.length() == 0) {
+ element.setAttribute("text", "true");
+ } else {
+ element.setAttributeNS(uri, prefix + ":text", "true");
+ }
+
+ }
+ }
+ }
+
+ /**
+ * Modify a document representation. This implementation of the abstract
+ * superclass method walks the document representation performing the
+ * following modifications: remove all content segments which consist only
+ * of whitespace; add an attribute "text" set to "true" to any elements
+ * which directly contain non-whitespace text content; and replace each
+ * non-whitespace text content segment with a "text" element which wraps
+ * the trimmed content.
+ *
+ * @param doc document representation to be modified
+ */
+
+ protected void modify(Object doc) {
+ modifyElement(((Document)doc).getDocumentElement());
+ }
+}
Added: webservices/axis2/trunk/archive/java/scratch/dennis/src/com/sosnoski/xmlbench/models/BenchDOM4J.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/archive/java/scratch/dennis/src/com/sosnoski/xmlbench/models/BenchDOM4J.java?rev=390489&view=auto
==============================================================================
--- webservices/axis2/trunk/archive/java/scratch/dennis/src/com/sosnoski/xmlbench/models/BenchDOM4J.java (added)
+++ webservices/axis2/trunk/archive/java/scratch/dennis/src/com/sosnoski/xmlbench/models/BenchDOM4J.java Fri Mar 31 11:59:03 2006
@@ -0,0 +1,254 @@
+/*
+ * 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.models;
+
+import java.io.*;
+import java.util.*;
+
+import org.dom4j.*;
+import org.dom4j.io.*;
+import org.xml.sax.*;
+
+import com.sosnoski.xmlbench.DocumentSummary;
+
+/**
+ * Benchmark for measuring performance of the dom4j document representation.
+ *
+ * @author Dennis M. Sosnoski
+ * @version 1.1
+ */
+
+public class BenchDOM4J extends BenchDocBase
+{
+ /** Class name to use for parser. */
+ protected String m_className;
+
+ /** SAX reader used within a test run. */
+ private SAXReader m_reader;
+
+ /** Document factory used within a test run (copied from reader). */
+ private DocumentFactory m_factory;
+
+ /** XML output serializer used within a test run. */
+ private XMLWriter m_writer;
+
+ /**
+ * Constructor.
+ *
+ * @param clas package-qualified name of class to be used for parser
+ */
+
+ public BenchDOM4J(String clas) {
+ super("dom4j");
+ m_className = clas;
+ }
+
+ /**
+ * Build document representation by parsing XML. This implementation
+ * creates a SAX reader if one does not already exist, then reuses
+ * that reader for the duration of a test run..
+ *
+ * @param in XML document input stream
+ * @return document representation
+ */
+
+ protected Object build(InputStream in) {
+ Object doc = null;
+ try {
+ if (m_reader == null) {
+ m_reader = new SAXReader(m_className, false);
+ XMLReader reader = m_reader.getXMLReader();
+ m_factory = m_reader.getDocumentFactory();
+ if (!reader.getClass().getName().equals(m_className)) {
+ System.out.println("dom4j found parser of class " +
+ reader.getClass().getName() + " instead of " +
+ m_className);
+ }
+ }
+ doc = m_reader.read(in);
+ } catch (Exception ex) {
+ ex.printStackTrace(System.out);
+ System.exit(0);
+ }
+ return doc;
+ }
+
+ /**
+ * Walk subtree for element. This recursively walks through the document
+ * nodes under an element, accumulating summary information.
+ *
+ * @param element element to be walked
+ * @param summary document summary information
+ */
+
+ protected void walkElement(Element element, DocumentSummary summary) {
+
+ // include attribute values in summary
+ int acnt = element.attributeCount();
+ for (int i = 0; i < acnt; i++) {
+ summary.addAttribute(element.attribute(i).getValue().length());
+ }
+
+ // loop through children
+ int ncnt = element.nodeCount();
+ for (int i = 0; i < ncnt; i++) {
+
+ // handle child by type
+ Node child = element.node(i);
+ int type = child.getNodeType();
+ if (type == Node.TEXT_NODE) {
+ summary.addContent(child.getText().length());
+ } else if (type == Node.ELEMENT_NODE) {
+ summary.addElements(1);
+ walkElement((Element)child, summary);
+ }
+
+ }
+ }
+
+ /**
+ * Walk and summarize document. This method walks through the nodes
+ * of the document, accumulating summary information.
+ *
+ * @param doc document representation to be walked
+ * @param summary output document summary information
+ */
+
+ protected void walk(Object doc, DocumentSummary summary) {
+ summary.addElements(1);
+ walkElement(((Document)doc).getRootElement(), summary);
+ }
+
+ /**
+ * Output a document as XML text. This method uses the method defined
+ * by dom4j to output a text representation of the document.
+ *
+ * @param doc document representation to be output
+ * @param out XML document output stream
+ */
+
+ protected void output(Object doc, OutputStream out) {
+ try {
+ if (m_writer == null) {
+ m_writer = new XMLWriter();
+ }
+ m_writer.setOutputStream(out);
+ m_writer.write((Document)doc);
+ m_writer.flush();
+ } catch (Exception ex) {
+ ex.printStackTrace(System.err);
+ System.exit(0);
+ }
+ }
+
+ /**
+ * Modify subtree for element. This recursively walks through the document
+ * nodes under an element, performing the modifications.
+ *
+ * @param element element to be walked
+ */
+
+ protected void modifyElement(Element element) {
+
+ // check for children present
+ if (element.nodeCount() > 0) {
+
+ // loop through child nodes
+ List children = element.content();
+ int ccnt = children.size();
+ QName qname = null;
+ boolean content = false;
+ for (int i = 0; i < ccnt; i++) {
+
+ // handle child by node type
+ Node child = (Node)children.get(i);
+ if (child.getNodeType() == Node.TEXT_NODE) {
+
+ // trim whitespace from content text
+ String trimmed = child.getText().trim();
+ if (trimmed.length() == 0) {
+
+ // delete child if only whitespace (adjusting index)
+ children.remove(i--);
+ --ccnt;
+
+ } else {
+
+ // construct qualified name for wrapper element
+ if (!content) {
+ qname = m_factory.createQName("text",
+ element.getNamespace());
+ content = true;
+ }
+
+ // wrap the trimmed content with new element
+ Element text = m_factory.createElement(qname);
+ text.addText(trimmed);
+ children.set(i, text);
+
+ }
+ } else if (child.getNodeType() == Node.ELEMENT_NODE) {
+
+ // handle child elements with recursive call
+ modifyElement((Element)child);
+
+ }
+ }
+
+ // check if we've seen any non-whitespace content for element
+ if (content) {
+
+ // add attribute flagging content found
+ element.addAttribute(qname, "true");
+
+ }
+ }
+ }
+
+ /**
+ * Modify a document representation. This implementation of the abstract
+ * superclass method walks the document representation performing the
+ * following modifications: remove all content segments which consist only
+ * of whitespace; add an attribute "text" set to "true" to any elements
+ * which directly contain non-whitespace text content; and replace each
+ * non-whitespace text content segment with a "text" element which wraps
+ * the trimmed content.
+ *
+ * @param doc document representation to be modified
+ */
+
+ protected void modify(Object doc) {
+/* modifyElement(((Document)doc).getRootElement()); */
+ }
+
+ /**
+ * Reset test class instance. This discards the SAX reader used
+ * within a test pass.
+ */
+
+ protected void reset() {
+ m_reader = null;
+ m_factory = null;
+ m_writer = null;
+ }
+}
Added: webservices/axis2/trunk/archive/java/scratch/dennis/src/com/sosnoski/xmlbench/models/BenchDOM4JStAX.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/archive/java/scratch/dennis/src/com/sosnoski/xmlbench/models/BenchDOM4JStAX.java?rev=390489&view=auto
==============================================================================
--- webservices/axis2/trunk/archive/java/scratch/dennis/src/com/sosnoski/xmlbench/models/BenchDOM4JStAX.java (added)
+++ webservices/axis2/trunk/archive/java/scratch/dennis/src/com/sosnoski/xmlbench/models/BenchDOM4JStAX.java Fri Mar 31 11:59:03 2006
@@ -0,0 +1,234 @@
+/*
+ * 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.models;
+
+import java.io.*;
+import java.util.*;
+
+import javax.xml.stream.FactoryConfigurationError;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamReader;
+
+import org.dom4j.*;
+import org.dom4j.io.*;
+import org.xml.sax.*;
+
+import com.sosnoski.xmlbench.DocumentSummary;
+
+/**
+ * Benchmark for measuring performance of the dom4j document representation using
+ * StAX event input and output.
+ *
+ * @author Dennis M. Sosnoski
+ */
+public class BenchDOM4JStAX extends BenchDocBase
+{
+ /** Input processor to build model. */
+ private STAXEventReader m_modelBuilder;
+
+ /** Document factory used within a test run (copied from reader). */
+ private DocumentFactory m_documentFactory;
+
+ /**
+ * Constructor.
+ */
+ public BenchDOM4JStAX() {
+ super("dom4j-stax");
+ }
+
+ /**
+ * Build document representation by parsing XML. This implementation
+ * creates a StAX reader for each document, since StAX readers are not
+ * reusable.
+ *
+ * @param in XML document input stream
+ * @return document representation
+ */
+ protected Object build(InputStream in) {
+ Object doc = null;
+ try {
+ if (m_modelBuilder == null) {
+ m_modelBuilder = new STAXEventReader();
+ }
+ doc = m_modelBuilder.readDocument(in);
+ } catch (Exception ex) {
+ ex.printStackTrace(System.out);
+ System.exit(0);
+ }
+ return doc;
+ }
+
+ /**
+ * Walk subtree for element. This recursively walks through the document
+ * nodes under an element, accumulating summary information.
+ *
+ * @param element element to be walked
+ * @param summary document summary information
+ */
+
+ protected void walkElement(Element element, DocumentSummary summary) {
+
+ // include attribute values in summary
+ int acnt = element.attributeCount();
+ for (int i = 0; i < acnt; i++) {
+ summary.addAttribute(element.attribute(i).getValue().length());
+ }
+
+ // loop through children
+ int ncnt = element.nodeCount();
+ for (int i = 0; i < ncnt; i++) {
+
+ // handle child by type
+ Node child = element.node(i);
+ int type = child.getNodeType();
+ if (type == Node.TEXT_NODE) {
+ summary.addContent(child.getText().length());
+ } else if (type == Node.ELEMENT_NODE) {
+ summary.addElements(1);
+ walkElement((Element)child, summary);
+ }
+
+ }
+ }
+
+ /**
+ * Walk and summarize document. This method walks through the nodes
+ * of the document, accumulating summary information.
+ *
+ * @param doc document representation to be walked
+ * @param summary output document summary information
+ */
+
+ protected void walk(Object doc, DocumentSummary summary) {
+ summary.addElements(1);
+ walkElement(((Document)doc).getRootElement(), summary);
+ }
+
+ /**
+ * Output a document as XML text. This method uses the method defined
+ * by dom4j to output a text representation of the document.
+ *
+ * @param doc document representation to be output
+ * @param out XML document output stream
+ */
+
+ protected void output(Object doc, OutputStream out) {
+ try {
+ STAXEventWriter writer = new STAXEventWriter(out);
+ writer.writeDocument((Document)doc);
+ } catch (Exception ex) {
+ ex.printStackTrace(System.err);
+ System.exit(0);
+ }
+ }
+
+ /**
+ * Modify subtree for element. This recursively walks through the document
+ * nodes under an element, performing the modifications.
+ *
+ * @param element element to be walked
+ */
+
+ protected void modifyElement(Element element) {
+
+ // check for children present
+ if (element.nodeCount() > 0) {
+
+ // loop through child nodes
+ List children = element.content();
+ int ccnt = children.size();
+ QName qname = null;
+ boolean content = false;
+ for (int i = 0; i < ccnt; i++) {
+
+ // handle child by node type
+ Node child = (Node)children.get(i);
+ if (child.getNodeType() == Node.TEXT_NODE) {
+
+ // trim whitespace from content text
+ String trimmed = child.getText().trim();
+ if (trimmed.length() == 0) {
+
+ // delete child if only whitespace (adjusting index)
+ children.remove(i--);
+ --ccnt;
+
+ } else {
+
+ // construct qualified name for wrapper element
+ if (!content) {
+ qname = m_documentFactory.createQName("text",
+ element.getNamespace());
+ content = true;
+ }
+
+ // wrap the trimmed content with new element
+ Element text = m_documentFactory.createElement(qname);
+ text.addText(trimmed);
+ children.set(i, text);
+
+ }
+ } else if (child.getNodeType() == Node.ELEMENT_NODE) {
+
+ // handle child elements with recursive call
+ modifyElement((Element)child);
+
+ }
+ }
+
+ // check if we've seen any non-whitespace content for element
+ if (content) {
+
+ // add attribute flagging content found
+ element.addAttribute(qname, "true");
+
+ }
+ }
+ }
+
+ /**
+ * Modify a document representation. This implementation of the abstract
+ * superclass method walks the document representation performing the
+ * following modifications: remove all content segments which consist only
+ * of whitespace; add an attribute "text" set to "true" to any elements
+ * which directly contain non-whitespace text content; and replace each
+ * non-whitespace text content segment with a "text" element which wraps
+ * the trimmed content.
+ *
+ * @param doc document representation to be modified
+ */
+
+ protected void modify(Object doc) {
+/* modifyElement(((Document)doc).getRootElement()); */
+ }
+
+ /**
+ * Reset test class instance. This discards the SAX reader used
+ * within a test pass.
+ */
+
+ protected void reset() {
+ m_modelBuilder = null;
+ m_documentFactory = null;
+ }
+}
Added: webservices/axis2/trunk/archive/java/scratch/dennis/src/com/sosnoski/xmlbench/models/BenchDocBase.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/archive/java/scratch/dennis/src/com/sosnoski/xmlbench/models/BenchDocBase.java?rev=390489&view=auto
==============================================================================
--- webservices/axis2/trunk/archive/java/scratch/dennis/src/com/sosnoski/xmlbench/models/BenchDocBase.java (added)
+++ webservices/axis2/trunk/archive/java/scratch/dennis/src/com/sosnoski/xmlbench/models/BenchDocBase.java Fri Mar 31 11:59:03 2006
@@ -0,0 +1,493 @@
+/*
+ * 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.models;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.io.NotSerializableException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.OutputStream;
+import java.io.PrintStream;
+
+import com.sosnoski.xmlbench.DocumentSummary;
+
+/**
+ * Abstract base class for document representation benchmark tests. This class
+ * defines the basic tests along with some implementation methods which must
+ * be defined by the subclass for each particular document representation to
+ * be tested.
+ *
+ * @author Dennis M. Sosnoski
+ */
+public abstract class BenchDocBase extends ModelBase
+{
+ /**
+ * Constructor.
+ *
+ * @param config test configuration name
+ */
+ protected BenchDocBase(String config) {
+ super(config);
+ }
+
+ /**
+ * Build document representation by parsing XML. This method must be
+ * implemented by each subclass to use the appropriate construction
+ * technique.
+ *
+ * @param in XML document input stream
+ * @return document representation
+ */
+ protected abstract Object build(InputStream in);
+
+ /**
+ * Walk and summarize document. This method should walk through the nodes
+ * of the document, accumulating summary information. It must be
+ * implemented by each subclass.
+ *
+ * @param doc document representation to be walked
+ * @param summary output document summary information
+ */
+ protected abstract void walk(Object doc, DocumentSummary summary);
+
+ /**
+ * Output a document as XML text. This method must be implemented by each
+ * subclass to use the appropriate output technique.
+ *
+ * @param doc document representation to be output
+ * @param out XML document output stream
+ */
+ protected abstract void output(Object document, OutputStream out);
+
+ /**
+ * Modify a document representation. This method must be implemented by each
+ * subclass to walk the document representation performing the following
+ * modifications: remove all content segments which consist only of
+ * whitespace; add an attribute "text" set to "true" to any elements which
+ * directly contain non-whitespace text content; and replace each
+ * non-whitespace text content segment with a "text" element which wraps
+ * the content.
+ *
+ * @param doc document representation to be modified
+ */
+ protected abstract void modify(Object document);
+
+ /**
+ * Reset test class instance. This method should be overridden by any
+ * subclasses which retain state information during the execution of a
+ * test. Any such information should be cleared when this method is called.
+ */
+ protected void reset() {}
+
+ /**
+ * Serialize a document to a byte array.
+ *
+ * @param doc document representation to be serialized
+ * @param out serialized document output stream
+ * @return <code>true</code> if successful, <code>false</code> if
+ * representation does not support serialization
+ */
+ protected boolean serialize(Object doc, OutputStream out) {
+ try {
+ ObjectOutputStream os = new ObjectOutputStream(out);
+ os.writeObject(doc);
+ os.close();
+ return true;
+ } catch (NotSerializableException ex) {
+ } catch (Exception ex) {
+ ex.printStackTrace(System.err);
+ System.exit(0);
+ }
+ return false;
+ }
+
+ /**
+ * Unserialize a document from a byte array.
+ *
+ * @param in serialized document input stream
+ * @return unserialized document representation
+ */
+ protected Object unserialize(InputStream in) {
+ Object restored = null;
+ try {
+ ObjectInputStream os = new ObjectInputStream(in);
+ restored = os.readObject();
+ } catch (Exception ex) {
+ ex.printStackTrace(System.err);
+ System.exit(0);
+ }
+ return restored;
+ }
+
+ /**
+ * Main time test method. This implementation of the abstract base class
+ * method performs the normal sequence of speed tests. Subclasses which
+ * cannot use the normal test sequence must override this method with
+ * their own variation.
+ *
+ * @param passes number of passes of each test
+ * @param excludes number of initialization passes excluded from averages
+ * @param texts document texts for test
+ * @return result times array
+ */
+ public int[] runTimeTest(int passes, int excludes, byte[][] texts) {
+
+ // allocate array for result values
+ int doccnt = texts.length;
+ int[] results = new int[TIME_RESULT_COUNT];
+ for (int i = 0; i < results.length; i++) {
+ results[i] = Integer.MIN_VALUE;
+ }
+
+ // create the reusable objects
+ ByteArrayInputStream[][] ins = new ByteArrayInputStream[passes][];
+ for (int i = 0; i < passes; i++) {
+ ins[i] = new ByteArrayInputStream[doccnt];
+ for (int j = 0; j < doccnt; j++) {
+ ins[i][j] = new ByteArrayInputStream(texts[j]);
+ }
+ }
+ ByteArrayOutputStream[] outs = new ByteArrayOutputStream[doccnt];
+ for (int i = 0; i < doccnt; i++) {
+ outs[i] = new ByteArrayOutputStream(texts[i].length*2);
+ }
+
+ // set start time for tests
+ initTime();
+
+ // first build the specified number of copies of the documents
+ Object[][] docs = new Object[passes][doccnt];
+ int best = Integer.MAX_VALUE;
+ int sum = 0;
+ for (int i = 0; i < passes; i++) {
+ for (int j = 0; j < doccnt; j++) {
+ docs[i][j] = build(ins[i][j]);
+ }
+ int time = testPassTime();
+ if (m_printPass) {
+ reportValue("Build document pass " + i, time);
+ }
+ if (best > time) {
+ best = time;
+ }
+ if (i >= excludes) {
+ sum += time;
+ }
+ }
+ results[BUILD_MIN_INDEX] = best;
+ results[BUILD_AVERAGE_INDEX] = sum / (passes - excludes);
+
+ // walk the constructed document copies
+ DocumentSummary info = new DocumentSummary();
+ best = Integer.MAX_VALUE;
+ sum = 0;
+ for (int i = 0; i < passes; i++) {
+ info.reset();
+ for (int j = 0; j < doccnt; j++) {
+ walk(docs[i][j], info);
+ }
+ int time = testPassTime();
+ if (m_printPass) {
+ reportValue("Walk document pass " + i, time);
+ }
+ if (best > time) {
+ best = time;
+ }
+ if (i >= excludes) {
+ sum += time;
+ }
+ }
+ results[WALK_MIN_INDEX] = best;
+ results[WALK_AVERAGE_INDEX] = sum / (passes - excludes);
+ results[BUILDWALK_MIN_INDEX] =
+ results[WALK_MIN_INDEX] + results[BUILD_MIN_INDEX];
+ results[BUILDWALK_AVERAGE_INDEX] =
+ results[WALK_AVERAGE_INDEX] + results[BUILD_AVERAGE_INDEX];
+
+ // generate text representation of document copies
+ byte[][] outputs = new byte[doccnt][];
+ best = Integer.MAX_VALUE;
+ sum = 0;
+ for (int i = 0; i < passes; i++) {
+ for (int j = 0; j < doccnt; j++) {
+ outs[j].reset();
+ output(docs[i][j], outs[j]);
+ }
+ int time = testPassTime();
+ if (m_printPass) {
+ reportValue("Generate text pass " + i, time);
+ }
+ if (best > time) {
+ best = time;
+ }
+ if (i >= excludes) {
+ sum += time;
+ }
+ }
+ results[TEXT_MIN_INDEX] = best;
+ results[TEXT_AVERAGE_INDEX] = sum / (passes - excludes);
+
+ // save copy of output for later check parse
+ for (int i = 0; i < doccnt; i++) {
+ outputs[i] = outs[i].toByteArray();
+ outs[i].reset();
+ }
+ initTime();
+
+ // check serialization support for document
+/* byte[][] serials = null;
+ Object[] restores = null;
+ int slength = 0;
+ if (!(docs[0][0] instanceof Serializable)) {
+ if (m_printPass) {
+ m_printStream.println
+ (" **Serialization not supported by model**");
+ }
+ } else {
+
+ // serialize with printing of times
+ best = Integer.MAX_VALUE;
+ sum = 0;
+ for (int i = 0; i < passes; i++) {
+ for (int j = 0; j < doccnt; j++) {
+ outs[j].reset();
+ serialize(docs[i][j], outs[j]);
+ }
+ int time = testPassTime();
+ if (m_printPass) {
+ reportValue("Serialize pass " + i, time);
+ }
+ if (best > time) {
+ best = time;
+ }
+ if (i >= excludes) {
+ sum += time;
+ }
+ }
+ results[SERIALIZE_MIN_INDEX] = best;
+ results[SERIALIZE_AVERAGE_INDEX] = sum / (passes - excludes);
+
+ // restore from serialized form
+ serials = new byte[doccnt][];
+ ByteArrayInputStream[] sins =
+ new ByteArrayInputStream[doccnt];
+ restores = new Object[doccnt];
+ for (int i = 0; i < doccnt; i++) {
+ serials[i] = outs[i].toByteArray();
+ sins[i] = new ByteArrayInputStream(serials[i]);
+ slength += serials[i].length;
+ }
+ results[SERIALIZE_SIZE_INDEX] = slength;
+ best = Integer.MAX_VALUE;
+ sum = 0;
+ for (int i = 0; i < passes; i++) {
+ for (int j = 0; j < doccnt; j++) {
+ sins[j].reset();
+ restores[j] = unserialize(sins[j]);
+ }
+ int time = testPassTime();
+ if (m_printPass) {
+ reportValue("Unserialize pass " + i, time);
+ }
+ if (best > time) {
+ best = time;
+ }
+ if (i >= excludes) {
+ sum += time;
+ }
+ }
+ results[UNSERIALIZE_MIN_INDEX] = best;
+ results[UNSERIALIZE_AVERAGE_INDEX] = sum / (passes - excludes);
+ } */
+
+ // modify the document representation
+ initTime();
+ best = Integer.MAX_VALUE;
+ sum = 0;
+ for (int i = 0; i < passes; i++) {
+ for (int j = 0; j < doccnt; j++) {
+ modify(docs[i][j]);
+ }
+ int time = testPassTime();
+ if (m_printPass) {
+ reportValue("Modify pass " + i, time);
+ }
+ if (best > time) {
+ best = time;
+ }
+ if (i >= excludes) {
+ sum += time;
+ }
+ }
+ results[MODIFY_MIN_INDEX] = best;
+ results[MODIFY_AVERAGE_INDEX] = sum / (passes - excludes);
+
+ // make sure generated text matches original document (outside timing)
+ Object[] checks = new Object[doccnt];
+ DocumentSummary verify = new DocumentSummary();
+ for (int i = 0; i < doccnt; i++) {
+ checks[i] = build(new ByteArrayInputStream(outputs[i]));
+ walk(checks[i], verify);
+ }
+ if (!info.structureEquals(verify)) {
+ PrintStream err = m_printStream != null ?
+ m_printStream : System.err;
+ err.println(" **" + getName() + " Error: " +
+ "Document built from output text does " +
+ "not match original document**");
+ printSummary(" Original", info, err);
+ printSummary(" Rebuild", verify, err);
+ }
+
+ // check if restored from serialized form
+/* if (restores != null) {
+
+ // validate the serialization for exact match (outside timing)
+ verify.reset();
+ for (int i = 0; i < doccnt; i++) {
+ walk(restores[i], verify);
+ }
+ if (!info.equals(verify)) {
+ PrintStream err = m_printStream != null ?
+ m_printStream : System.err;
+ err.println(" **" + getName() + " Error: " +
+ "Document built from output text does " +
+ "not match original document**");
+ printSummary(" Original", info, err);
+ printSummary(" Rebuild", verify, err);
+ }
+ } */
+
+ // copy document summary values for return
+ results[ELEMENT_COUNT_INDEX] = info.getElementCount();
+ results[ATTRIBUTE_COUNT_INDEX] = info.getAttributeCount();
+ results[CONTENT_COUNT_INDEX] = info.getContentCount();
+ results[TEXTCHAR_COUNT_INDEX] = info.getTextCharCount();
+ results[ATTRCHAR_COUNT_INDEX] = info.getAttrCharCount();
+
+ // print summary for document
+ if (m_printSummary) {
+ printSummary(" Document", info, m_printStream);
+ int ilength = 0;
+ int olength = 0;
+ for (int i = 0; i < doccnt; i++) {
+ ilength += texts[i].length;
+ olength += outputs[i].length;
+ }
+ m_printStream.println(" Original text size was " + ilength +
+ ", output text size was " + olength);
+/* if (serials != null) {
+ m_printStream.println(" Serialized length was " + slength);
+ } */
+/* info.reset();
+ walk(docs[0][0], info);
+ printSummary(" Modified document", info, m_printStream); */
+ }
+ reset();
+ return results;
+ }
+
+ /**
+ * Main space test method. This implementation of the abstract base class
+ * method performs the normal sequence of space tests.
+ *
+ * @param passes number of passes of each test
+ * @param excludes number of initialization passes excluded from averages
+ * @param texts document texts for test
+ * @return result values array
+ */
+ public int[] runSpaceTest(int passes, int excludes, byte[][] texts) {
+
+ // allocate array for result values
+ int[] results = new int[SPACE_RESULT_COUNT];
+ for (int i = 0; i < results.length; i++) {
+ results[i] = Integer.MIN_VALUE;
+ }
+
+ // create the reusable objects
+ int doccnt = texts.length;
+ ByteArrayInputStream[][] ins = new ByteArrayInputStream[passes][];
+ for (int i = 0; i < passes; i++) {
+ ins[i] = new ByteArrayInputStream[doccnt];
+ for (int j = 0; j < doccnt; j++) {
+ ins[i][j] = new ByteArrayInputStream(texts[j]);
+ }
+ }
+ DocumentSummary info = new DocumentSummary();
+
+ // initialize memory information for tests
+ initMemory();
+ results[INITIAL_MEMORY_INDEX] = (int)m_lastMemory;
+
+ // first build the documents
+ Object[][] docs = new Object[passes][doccnt];
+ int base = (int)m_lastMemory;
+ for (int i = 0; i < passes; i++) {
+ for (int j = 0; j < doccnt; j++) {
+ docs[i][j] = build(ins[i][j]);
+ }
+ if (i == 0) {
+ results[FIRST_SPACE_INDEX] = testPassSpace();
+ if (excludes == 1) {
+ base = (int)m_lastMemory;
+ }
+ } else if ((i+1) == excludes) {
+ testPassSpace();
+ base = (int)m_lastMemory;
+ }
+ if (m_printPass) {
+ reportValue("Build document pass " + i, testPassSpace());
+ }
+ }
+ testPassSpace();
+ results[AVERAGE_SPACE_INDEX] =
+ ((int)m_lastMemory-base) / (passes - excludes);
+
+ // now walk the constructed document copies
+ base = (int)m_lastMemory;
+ for (int i = excludes; i < passes; i++) {
+ info.reset();
+ for (int j = 0; j < doccnt; j++) {
+ walk(docs[i][j], info);
+ }
+ if (m_printPass) {
+ reportValue("Walk document pass " + i, testPassSpace());
+ }
+ }
+ testPassSpace();
+ results[WALKED_CHANGE_INDEX] =
+ ((int)m_lastMemory-base) / (passes - excludes);
+ results[WALKED_SPACE_INDEX] = results[AVERAGE_SPACE_INDEX] +
+ results[WALKED_CHANGE_INDEX];
+
+ // free all constructed objects to find final space
+ docs = null;
+ reset();
+ initMemory();
+ results[DELTA_MEMORY_INDEX] =
+ (int)m_lastMemory - results[INITIAL_MEMORY_INDEX];
+ return results;
+ }
+}
\ No newline at end of file
Added: webservices/axis2/trunk/archive/java/scratch/dennis/src/com/sosnoski/xmlbench/models/BenchJDOM.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/archive/java/scratch/dennis/src/com/sosnoski/xmlbench/models/BenchJDOM.java?rev=390489&view=auto
==============================================================================
--- webservices/axis2/trunk/archive/java/scratch/dennis/src/com/sosnoski/xmlbench/models/BenchJDOM.java (added)
+++ webservices/axis2/trunk/archive/java/scratch/dennis/src/com/sosnoski/xmlbench/models/BenchJDOM.java Fri Mar 31 11:59:03 2006
@@ -0,0 +1,248 @@
+/*
+ * 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.models;
+
+import java.io.*;
+import java.util.*;
+
+import javax.xml.parsers.*;
+
+import org.jdom.*;
+import org.jdom.input.*;
+import org.jdom.output.*;
+
+import com.sosnoski.xmlbench.DocumentSummary;
+
+/**
+ * Benchmark for measuring performance of the JDOM document representation.
+ *
+ * @author Dennis M. Sosnoski
+ * @version 1.2
+ */
+
+public class BenchJDOM extends BenchDocBase
+{
+ /** Class name to use for parser. */
+ protected String m_className;
+
+ /** SAX builder used within a test run. */
+ private SAXBuilder m_builder;
+
+ /** XML outputter used within a test run. */
+ private XMLOutputter m_outputter;
+
+ /**
+ * Constructor.
+ *
+ * @param clas package-qualified name of class to be used for parser
+ */
+
+ public BenchJDOM(String clas) {
+ super("JDOM");
+ m_className = clas;
+ }
+
+ /**
+ * Build document representation by parsing XML. This implementation
+ * creates a SAX builder if one does not already exist, then reuses
+ * that builder for the duration of a test run..
+ *
+ * @param in XML document input stream
+ * @return document representation
+ */
+
+ protected Object build(InputStream in) {
+ if (m_builder == null) {
+ m_builder = new SAXBuilder(m_className, false);
+ }
+ Object doc = null;
+ try {
+ doc = m_builder.build(in);
+ } catch (Exception ex) {
+ ex.printStackTrace(System.err);
+ System.exit(0);
+ }
+ return doc;
+ }
+
+ /**
+ * Walk subtree for element. This recursively walks through the document
+ * nodes under an element, accumulating summary information.
+ *
+ * @param element element to be walked
+ * @param summary document summary information
+ */
+
+ protected void walkElement(Element element, DocumentSummary summary) {
+
+ // include attribute values in summary
+ List list = element.getAttributes();
+ int acnt = list.size();
+ for (int i = 0; i < acnt; i++) {
+ Attribute attr = (Attribute)list.get(i);
+ summary.addAttribute(attr.getValue().length());
+ }
+
+ // loop through children
+ list = element.getContent();
+ int ncnt = list.size();
+ for (int i = 0; i < ncnt; i++) {
+
+ // handle child by type
+ Object child = list.get(i);
+ if (child instanceof Text) {
+ summary.addContent(((Text)child).getText().length());
+ } else if (child instanceof Element) {
+ summary.addElements(1);
+ walkElement((Element)child, summary);
+ }
+
+ }
+ }
+
+ /**
+ * Walk and summarize document. This method walks through the nodes
+ * of the document, accumulating summary information.
+ *
+ * @param doc document representation to be walked
+ * @param summary output document summary information
+ */
+
+ protected void walk(Object doc, DocumentSummary summary) {
+ summary.addElements(1);
+ walkElement(((Document)doc).getRootElement(), summary);
+ }
+
+ /**
+ * Output a document as XML text. This method uses the method defined
+ * by JDOM to output a text representation of the document.
+ *
+ * @param doc document representation to be output
+ * @param out XML document output stream
+ */
+
+ protected void output(Object doc, OutputStream out) {
+ if (m_outputter == null) {
+ m_outputter = new XMLOutputter();
+ }
+ try {
+ m_outputter.output((Document)doc, out);
+ } catch (Exception ex) {
+ ex.printStackTrace(System.err);
+ System.exit(0);
+ }
+ }
+
+ /**
+ * Modify subtree for element. This recursively walks through the document
+ * nodes under an element, performing the modifications.
+ *
+ * @param element element to be walked
+ */
+
+ protected void modifyElement(Element element) {
+
+ // check for children present
+ List children = element.getContent();
+ if (children.size() > 0) {
+
+ // loop through child nodes
+ int ccnt = children.size();
+ Namespace namespace = null;
+ boolean content = false;
+ for (int i = 0; i < ccnt; i++) {
+
+ // handle child by node type
+ Object child = children.get(i);
+ if (child instanceof Text) {
+
+ // trim whitespace from content text
+ String trimmed = ((Text)child).getTextTrim();
+ if (trimmed.length() == 0) {
+
+ // delete child if only whitespace (adjusting index)
+ children.remove(i--);
+ --ccnt;
+
+ } else {
+
+ // set namespace if first content found
+ if (!content) {
+ namespace = element.getNamespace();
+ content = true;
+ }
+
+ // wrap the trimmed content with new element
+ Element text = new Element("text", namespace);
+ text.setText(trimmed);
+ children.set(i, text);
+
+ }
+ } else if (child instanceof Element) {
+
+ // handle child elements with recursive call
+ modifyElement((Element)child);
+
+ }
+ }
+
+ // check if we've seen any non-whitespace content for element
+ if (content) {
+
+ // add attribute flagging content found
+ if (namespace.getPrefix().length() == 0) {
+ element.setAttribute("text", "true");
+ } else {
+ element.setAttribute("text", "true", namespace);
+ }
+
+ }
+ }
+ }
+
+ /**
+ * Modify a document representation. This implementation of the abstract
+ * superclass method walks the document representation performing the
+ * following modifications: remove all content segments which consist only
+ * of whitespace; add an attribute "text" set to "true" to any elements
+ * which directly contain non-whitespace text content; and replace each
+ * non-whitespace text content segment with a "text" element which wraps
+ * the trimmed content.
+ *
+ * @param doc document representation to be modified
+ */
+
+ protected void modify(Object doc) {
+ modifyElement(((Document)doc).getRootElement());
+ }
+
+ /**
+ * Reset test class instance. This discards the SAX builder used
+ * within a test pass.
+ */
+
+ protected void reset() {
+ m_builder = null;
+ m_outputter = null;
+ }
+}
Added: webservices/axis2/trunk/archive/java/scratch/dennis/src/com/sosnoski/xmlbench/models/BenchXerces2.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/archive/java/scratch/dennis/src/com/sosnoski/xmlbench/models/BenchXerces2.java?rev=390489&view=auto
==============================================================================
--- webservices/axis2/trunk/archive/java/scratch/dennis/src/com/sosnoski/xmlbench/models/BenchXerces2.java (added)
+++ webservices/axis2/trunk/archive/java/scratch/dennis/src/com/sosnoski/xmlbench/models/BenchXerces2.java Fri Mar 31 11:59:03 2006
@@ -0,0 +1,152 @@
+/*
+ * 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.models;
+
+import java.io.*;
+import java.util.*;
+
+import javax.xml.parsers.*;
+
+import org.apache.xerces.dom.*;
+import org.apache.xerces.parsers.*;
+import org.apache.xml.serialize.*;
+
+import org.w3c.dom.*;
+
+import org.xml.sax.*;
+
+/**
+ * Abstract base class for benchmarks measuring performance of the Xerces2 DOM
+ * document representation. This base class implementation can be customized
+ * by subclasses to experiment with options for the representation, in
+ * particular for trying the deferred node expansion feature of Xerces. The
+ * code used for Xerces2 DOM is identical to that used for Xerces1, but is
+ * compiled with a different classpath.
+ *
+ * @author Dennis M. Sosnoski
+ * @version 1.1
+ */
+
+public abstract class BenchXerces2 extends BenchDOM
+{
+ /** Flag for using deferred node expansion. */
+ private boolean m_deferExpansion;
+
+ /** DOM parser used within a test run. */
+ private DOMParser m_parser;
+
+ /** XML output serializer used within a test run. */
+ private XMLSerializer m_serializer;
+
+ /**
+ * Constructor.
+ *
+ * @param config test configuration name
+ * @param defer defer node expansion flag
+ */
+
+ protected BenchXerces2(String config, boolean defer) {
+ super(config);
+ m_deferExpansion = defer;
+ }
+
+ /**
+ * Set deferred node expansion mode.
+ *
+ * @param defer defer node expansion flag
+ */
+
+ protected void setDeferExpansion(boolean defer) {
+ m_deferExpansion = defer;
+ }
+
+ /**
+ * Build document representation by parsing XML. This implementation
+ * creates a DOM parser if one does not already exist, then reuses
+ * that parser for the duration of a test run..
+ *
+ * @param in XML document input stream
+ * @return document representation
+ */
+
+ protected Object build(InputStream in) {
+ if (m_parser == null) {
+ m_parser = new DOMParser();
+ try {
+ m_parser.setFeature
+ ("http://xml.org/sax/features/validation", false);
+ m_parser.setFeature
+ ("http://apache.org/xml/features/dom/defer-node-expansion",
+ m_deferExpansion);
+ m_parser.setFeature
+ ("http://xml.org/sax/features/namespaces", true);
+ } catch (Exception ex) {
+ ex.printStackTrace(System.err);
+ System.exit(0);
+ }
+ }
+ Object doc = null;
+ try {
+ m_parser.parse(new InputSource(in));
+ doc = m_parser.getDocument();
+ m_parser.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
+ * @param out XML document output stream
+ */
+
+ protected void output(Object doc, OutputStream out) {
+ if (m_serializer == null) {
+ OutputFormat format = new OutputFormat((Document)doc);
+ m_serializer = new XMLSerializer(format);
+ }
+ try {
+ m_serializer.reset();
+ m_serializer.setOutputByteStream(out);
+ m_serializer.serialize(((Document)doc).getDocumentElement());
+ } catch (Exception ex) {
+ ex.printStackTrace(System.err);
+ System.exit(0);
+ }
+ }
+
+ /**
+ * Reset test class instance. This discards the parser used
+ * within a test pass.
+ */
+
+ protected void reset() {
+ m_parser = null;
+ m_serializer = null;
+ }
+}
Added: webservices/axis2/trunk/archive/java/scratch/dennis/src/com/sosnoski/xmlbench/models/BenchXerces2Base.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/archive/java/scratch/dennis/src/com/sosnoski/xmlbench/models/BenchXerces2Base.java?rev=390489&view=auto
==============================================================================
--- webservices/axis2/trunk/archive/java/scratch/dennis/src/com/sosnoski/xmlbench/models/BenchXerces2Base.java (added)
+++ webservices/axis2/trunk/archive/java/scratch/dennis/src/com/sosnoski/xmlbench/models/BenchXerces2Base.java Fri Mar 31 11:59:03 2006
@@ -0,0 +1,42 @@
+/*
+ * 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.models;
+
+/**
+ * Benchmark for measuring performance of the Xerces2 DOM document
+ * representation with deferred node expansion disabled.
+ *
+ * @author Dennis M. Sosnoski
+ * @version 1.1
+ */
+
+public class BenchXerces2Base extends BenchXerces2
+{
+ /**
+ * Constructor.
+ */
+
+ public BenchXerces2Base() {
+ super("Xerces2 DOM", false);
+ }
+}
Added: webservices/axis2/trunk/archive/java/scratch/dennis/src/com/sosnoski/xmlbench/models/BenchXerces2Deferred.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/archive/java/scratch/dennis/src/com/sosnoski/xmlbench/models/BenchXerces2Deferred.java?rev=390489&view=auto
==============================================================================
--- webservices/axis2/trunk/archive/java/scratch/dennis/src/com/sosnoski/xmlbench/models/BenchXerces2Deferred.java (added)
+++ webservices/axis2/trunk/archive/java/scratch/dennis/src/com/sosnoski/xmlbench/models/BenchXerces2Deferred.java Fri Mar 31 11:59:03 2006
@@ -0,0 +1,42 @@
+/*
+ * 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.models;
+
+/**
+ * Benchmark for measuring performance of the Xerces2 DOM document
+ * representation with deferred node expansion enabled.
+ *
+ * @author Dennis M. Sosnoski
+ * @version 1.1
+ */
+
+public class BenchXerces2Deferred extends BenchXerces2
+{
+ /**
+ * Constructor.
+ */
+
+ public BenchXerces2Deferred() {
+ super("Xerces2 def.", true);
+ }
+}
Added: webservices/axis2/trunk/archive/java/scratch/dennis/src/com/sosnoski/xmlbench/models/ModelBase.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/archive/java/scratch/dennis/src/com/sosnoski/xmlbench/models/ModelBase.java?rev=390489&view=auto
==============================================================================
--- webservices/axis2/trunk/archive/java/scratch/dennis/src/com/sosnoski/xmlbench/models/ModelBase.java (added)
+++ webservices/axis2/trunk/archive/java/scratch/dennis/src/com/sosnoski/xmlbench/models/ModelBase.java Fri Mar 31 11:59:03 2006
@@ -0,0 +1,207 @@
+/*
+ * 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.models;
+
+import java.io.*;
+
+import java.util.*;
+
+import com.sosnoski.xmlbench.*;
+
+/**
+ * Base class for XML benchmark tests. This class provides some basic methods
+ * used by the testing. It must be subclassed for each particular parser or
+ * document representation to be tested.
+ *
+ * @author Dennis M. Sosnoski
+ */
+public abstract class ModelBase extends TestBase
+{
+ // Indices for vector of values returned by time test
+ /** Best document build time result index. */
+ public static final int BUILD_MIN_INDEX = 0;
+ /** Average document build time result index. */
+ public static final int BUILD_AVERAGE_INDEX = 1;
+ /** Best document walk time result index. */
+ public static final int WALK_MIN_INDEX = 2;
+ /** Average document walk time result index. */
+ public static final int WALK_AVERAGE_INDEX = 3;
+ /** Sum of best build and walk time result index. */
+ public static final int BUILDWALK_MIN_INDEX = 4;
+ /** Sum of average build and walk time result index. */
+ public static final int BUILDWALK_AVERAGE_INDEX = 5;
+ /** Best document text generation time result index. */
+ public static final int TEXT_MIN_INDEX = 6;
+ /** Average document text generation time result index. */
+ public static final int TEXT_AVERAGE_INDEX = 7;
+ /** Best serialization time result index. */
+ public static final int SERIALIZE_MIN_INDEX = 8;
+ /** Average serialization time result index. */
+ public static final int SERIALIZE_AVERAGE_INDEX = 9;
+ /** Best unserialization time walk time result index. */
+ public static final int UNSERIALIZE_MIN_INDEX = 10;
+ /** Average unserialization time walk time result index. */
+ public static final int UNSERIALIZE_AVERAGE_INDEX = 11;
+ /** Best modification time result index. */
+ public static final int MODIFY_MIN_INDEX = 12;
+ /** Average modification time result index. */
+ public static final int MODIFY_AVERAGE_INDEX = 13;
+ /** Serialized size result index. */
+ public static final int SERIALIZE_SIZE_INDEX = 14;
+ /** Element count index. */
+ public static final int ELEMENT_COUNT_INDEX = 15;
+ /** Content text segment count index. */
+ public static final int CONTENT_COUNT_INDEX = 16;
+ /** Attribute count index. */
+ public static final int ATTRIBUTE_COUNT_INDEX = 17;
+ /** Text character count index. */
+ public static final int TEXTCHAR_COUNT_INDEX = 18;
+ /** Attribute character count index. */
+ public static final int ATTRCHAR_COUNT_INDEX = 19;
+ /** Count of result values returned. */
+ public static final int TIME_RESULT_COUNT = 20;
+
+ // Indices for vector of values returned by space test
+ /** Initial memory usage (before document construction). */
+ public static final int INITIAL_MEMORY_INDEX = 0;
+ /** Net change in memory usage from start to end. */
+ public static final int DELTA_MEMORY_INDEX = 1;
+ /** First document memory usage. */
+ public static final int FIRST_SPACE_INDEX = 2;
+ /** Average document memory usage. */
+ public static final int AVERAGE_SPACE_INDEX = 3;
+ /** Memory usage change after walking document. */
+ public static final int WALKED_CHANGE_INDEX = 4;
+ /** Total memory usage for built and walked document. */
+ public static final int WALKED_SPACE_INDEX = 5;
+ /** Count of result values returned. */
+ public static final int SPACE_RESULT_COUNT = 6;
+
+ /** Abbreviated descriptions of time test result values. */
+ static public final String[] s_timeShortDescriptions =
+ {
+ "Build mn",
+ "Build av",
+ "Walk mn",
+ "Walk av",
+ "Build-Walk mn",
+ "Build-Walk av",
+ "Write mn",
+ "Write av",
+ "Ser mn",
+ "Ser av",
+ "Unser mn",
+ "Unser av",
+ "Mod mn",
+ "Mod av",
+ "Ser sz",
+ "Elems",
+ "Conts",
+ "Attrs",
+ "Text ch",
+ "Attr ch"
+ };
+
+ /** Full descriptions of time test result values. */
+ static public final String[] s_timeFullDescriptions =
+ {
+ "Build document minimum time (ms)",
+ "Build document average time (ms)",
+ "Walk document minimum time (ms)",
+ "Walk document average time (ms)",
+ "Sum of build and walk minimum times (ms)",
+ "Sum of build and walk average times (ms)",
+ "Write document text minimum time (ms)",
+ "Write document text average time (ms)",
+ "Serialize document minimum time (ms)",
+ "Serialize document average time (ms)",
+ "Unserialize document minimum time (ms)",
+ "Unserialize document average time (ms)",
+ "Modify document minimum time (ms)",
+ "Modify document average time (ms)",
+ "Serialized document size (bytes)",
+ "Elements in document",
+ "Content text segments in document",
+ "Attributes in document",
+ "Text content characters in document",
+ "Attribute value characters in document"
+ };
+
+ /** Abbreviated descriptions of space test result values. */
+ static public final String[] s_spaceShortDescriptions =
+ {
+ "Init mem",
+ "Chg mem",
+ "First sz",
+ "Avg sz",
+ "Walked sz",
+ "Avg+Walked sz"
+ };
+
+ /** Full descriptions of space test result values. */
+ static public final String[] s_spaceFullDescriptions =
+ {
+ "Initial memory usage before document parse (bytes)",
+ "Net change in memory usage (bytes)",
+ "First document copy memory size (bytes)",
+ "Average document copy memory size (bytes)",
+ "Average walked document memory increase (bytes)",
+ "Average document memory size after walking (bytes)"
+ };
+
+ /**
+ * Constructor.
+ *
+ * @param config test configuration name
+ */
+
+ protected ModelBase(String config) {
+ super(config);
+ }
+
+ /**
+ * Main time test method. This must be implemented by the subclass to
+ * perform the sequence of speed tests appropriate to the test
+ * platform.
+ *
+ * @param passes number of passes of each test
+ * @param excludes number of initialization passes excluded from averages
+ * @param texts document texts for test
+ * @return result times array
+ */
+
+ public abstract int[] runTimeTest(int passes, int excludes, byte[][] texts);
+
+ /**
+ * Main space test method. This must be implemented by the subclass to
+ * perform the sequence of space tests appropriate to the test
+ * platform.
+ *
+ * @param passes number of passes of each test
+ * @param excludes number of initialization passes excluded from averages
+ * @param texts document texts for test
+ * @return result spaces array
+ */
+
+ public abstract int[] runSpaceTest(int passes, int excludes, byte[][] texts);
+}
Added: webservices/axis2/trunk/archive/java/scratch/dennis/try.sh
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/archive/java/scratch/dennis/try.sh?rev=390489&view=auto
==============================================================================
--- webservices/axis2/trunk/archive/java/scratch/dennis/try.sh (added)
+++ webservices/axis2/trunk/archive/java/scratch/dennis/try.sh Fri Mar 31 11:59:03 2006
@@ -0,0 +1,10 @@
+java -Xms512M -Xmx512M -cp bin:lib/jaxp.jar:lib/Piccolo.jar:lib/jdom.jar com.sosnoski.xmlbench.XMLBench -sb -u com.bluecast.xml.Piccolo jdom docs/init.xml docs/xmlformatter.xml docs/soaps
+java -Xms512M -Xmx512M -cp bin:lib/jaxp.jar:lib/Piccolo.jar:lib/dom4j.jar com.sosnoski.xmlbench.XMLBench -sb -u com.bluecast.xml.Piccolo dom4j docs/init.xml docs/xmlformatter.xml docs/soaps
+#java -Xms512M -Xmx512M -cp bin:lib/dom4j.jar:lib/stax-api-1.0.jar:lib/wstx-asl-2.8.2.jar com.sosnoski.xmlbench.XMLBench -sb dom4jstax docs/init.xml docs/xmlformatter.xml docs/soaps
+java -Xms512M -Xmx512M -cp bin:lib/xmlParserAPIs.jar:lib/xercesImpl.jar com.sosnoski.xmlbench.XMLBench -sb xerces2 docs/init.xml docs/xmlformatter.xml docs/soaps
+java -Xms512M -Xmx512M -cp bin:lib/axiom-api-SNAPSHOT.jar:lib/axiom-impl-SNAPSHOT.jar:lib/stax-api-1.0.jar:lib/wstx-asl-2.8.2.jar com.sosnoski.xmlbench.XMLBench -sb axiom docs/init.xml docs/xmlformatter.xml docs/soaps
+java -Xms512M -Xmx512M -cp bin:lib/jaxp.jar:lib/Piccolo.jar:lib/jdom.jar com.sosnoski.xmlbench.XMLBench -sbmp4n -u com.bluecast.xml.Piccolo jdom docs/init.xml docs/xmlformatter.xml docs/soaps
+java -Xms512M -Xmx512M -cp bin:lib/jaxp.jar:lib/Piccolo.jar:lib/dom4j.jar com.sosnoski.xmlbench.XMLBench -sbmp4n -u com.bluecast.xml.Piccolo dom4j docs/init.xml docs/xmlformatter.xml docs/soaps
+#java -Xms512M -Xmx512M -cp bin:lib/dom4j.jar:lib/stax-api-1.0.jar:lib/wstx-asl-2.8.2.jar com.sosnoski.xmlbench.XMLBench -sbmp4n dom4jstax docs/init.xml docs/xmlformatter.xml docs/soaps
+java -Xms512M -Xmx512M -cp bin:lib/xmlParserAPIs.jar:lib/xercesImpl.jar com.sosnoski.xmlbench.XMLBench -sbmp4n xerces2 docs/init.xml docs/xmlformatter.xml docs/soaps
+java -Xms512M -Xmx512M -cp bin:lib/axiom-api-SNAPSHOT.jar:lib/axiom-impl-SNAPSHOT.jar:lib/stax-api-1.0.jar:lib/wstx-asl-2.8.2.jar com.sosnoski.xmlbench.XMLBench -sbmp4n axiom docs/init.xml docs/xmlformatter.xml docs/soaps