Glen, Could up please send the bigfile.xml as well? Better to do it via JIRA.
thanks, dims On 3/30/06, Glen Daniels <[EMAIL PROTECTED]> wrote: > Hi folks: > > The following is a quick test which takes an XML input file, parses it, > and walks the tree collecting all text content. It does this using both > JDOM (note that you'll need the StAXBuilder and StAXTextModifier which > you can find at http://svn.woodstox.codehaus.org/utils/jdom/) and AXIOM, > 100 times each, and then averages the timings. The code is as close to > identical as I could get for the two packages. > > For the file I'm working with (about 150K) I'm seeing AXIOM get an > average time around 180ms, whereas JDOM comes in at around 77ms. The > strings match up. This could be better, because frankly JDOM is way > easier to use. :) > > I think it might be time to integrate some performance testing into our > builds, and to do some optimization on AXIOM. I haven't yet looked at > comparing memory footprints, but may try to do that sometime soon. > > --Glen > > -------- > > import org.apache.axiom.om.OMXMLParserWrapper; > import org.apache.axiom.om.OMAbstractFactory; > import org.apache.axiom.om.OMElement; > import org.apache.axiom.om.OMNode; > import org.apache.axiom.om.impl.llom.factory.OMXMLBuilderFactory; > import org.jdom.input.StAXBuilder; > import org.jdom.Document; > import org.jdom.Element; > import org.jdom.Content; > > import javax.xml.stream.XMLStreamReader; > import javax.xml.stream.XMLInputFactory; > import java.io.FileInputStream; > import java.util.Iterator; > import java.util.List; > import java.util.Date; > > public class Test { > static class Timer { > long startTime; > long stopTime; > > public void start() { > startTime = new Date().getTime(); > } > > public long stop() { > stopTime = new Date().getTime(); > return (stopTime - startTime); > } > } > > // A place to save the string length for comparison purposes > static int strLen = 0; > > public static void main(String[] args) throws Exception { > // Replace with any big file > String FILENAME = "Scratch/bigfile.xml"; > > int NUM_RUNS = 100; > long accum = 0; > > for (int i = 0; i < NUM_RUNS; i++) { > FileInputStream fis = new FileInputStream(FILENAME); > XMLStreamReader parser = > XMLInputFactory.newInstance().createXMLStreamReader(fis); > accum += runAXIOMTest(parser); > parser.close(); > fis.close(); > } > System.out.println("OM avg was " + (accum / NUM_RUNS) + > " (" + strLen + ")"); > > strLen = 0; > accum = 0; > > for (int i = 0; i < NUM_RUNS; i++) { > FileInputStream fis = new FileInputStream(FILENAME); > XMLStreamReader parser = > XMLInputFactory.newInstance().createXMLStreamReader(fis); > accum += runJDOMTest(parser); > parser.close(); > fis.close(); > } > System.out.println("JDOM avg was " + (accum / NUM_RUNS) + > " (" + strLen + ")"); > } > > public static long runAXIOMTest(XMLStreamReader parser) throws > Exception { > Timer t = new Timer(); > t.start(); > OMXMLParserWrapper builder = > OMXMLBuilderFactory.createStAXOMBuilder(OMAbstractFactory.getOMFactory(), > parser); > OMElement root = builder.getDocumentElement(); > StringBuffer buf = new StringBuffer(); > genAXIOMString(root, buf); > long elapsed = t.stop(); > if (strLen == 0) { > // System.out.println("[" + buf.toString() + "]"); > strLen = buf.length(); > } > return elapsed; > } > > public static long runJDOMTest(XMLStreamReader parser) throws > Exception { > Timer t = new Timer(); > t.start(); > StAXBuilder builder = new StAXBuilder(); > Document doc = builder.build(parser); > StringBuffer buf = new StringBuffer(); > Element root = doc.getRootElement(); > genJDOMString(root, buf); > long elapsed = t.stop(); > if (strLen == 0) { > // System.out.println("[" + buf.toString() + "]"); > strLen = buf.length(); > } > return elapsed; > } > > // These two methods do the exact same thing, one for AXIOM and one > // for JDOM. Walk the tree and collect all the text. > > public static void genAXIOMString(OMElement el, StringBuffer buf) { > buf.append(el.getText()); > Iterator i = el.getChildren(); > while (i.hasNext()) { > OMNode node = (OMNode)i.next(); > if (node instanceof OMElement) { > OMElement element = (OMElement) node; > genAXIOMString(element, buf); > } > } > } > > public static void genJDOMString(Element el, StringBuffer buf) { > buf.append(el.getText()); > List children = el.getChildren(); > for (Iterator i = children.iterator(); i.hasNext();) { > Content content = (Content)i.next(); > if (content instanceof Element) { > Element element = (Element)content; > genJDOMString(element, buf); > } > } > } > } > -- Davanum Srinivas : http://wso2.com/blogs/
