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 gd...@macromedia.com on 2001/04/03 20:14:04 UTC

FYI : JDOM vs. DOM

Out of curiousity, I whipped up a VERY quick test based on the Xerces
DOMCount sample.  I parsed and traversed a document with 21 elements, 41
attributes, and 61 characters 10 times each, using DOM and JDOM object
models.

With DOM, the first run took 219ms.  After that the next 9 were each between
31 and 78 ms.

With JDOM, the first run took 16ms.  The next 9 were all the same, 0ms.

This is not in any way a conclusive test, since the models aren't really
quite the same and I wasn't paying attention to caching, etc...  However I
do believe it's indicative of the trend here.  Code is attached (I built
both of these in the xerces samples/dom dir).

Glen Daniels
Macromedia
Engineering Manager
http://www.macromedia.com/
                                Building cool stuff for web developers



Re: FYI : JDOM vs. DOM

Posted by Aleksander Slominski <as...@cs.indiana.edu>.
gdaniels@macromedia.com wrote:

> With JDOM, the first run took 16ms.  The next 9 were all the same, 0ms.

that is pretty blazing speed (0ms?) so i got very curious here are snippets from your code:


     try {
            DOMParserWrapper parser =
            (DOMParserWrapper)Class.forName(parserWrapperName).newInstance();
            DOMCount counter = new DOMCount();
            long before = System.currentTimeMillis();
            parser.setFeature( "http://apache.org/xml/features/dom/defer-node-expansion",

                               setDeferredDOM );
            parser.setFeature( "http://xml.org/sax/features/validation",
                               setValidation );
            parser.setFeature( "http://xml.org/sax/features/namespaces",
                               setNameSpaces );
            parser.setFeature( "http://apache.org/xml/features/validation/schema",
                               setSchemaSupport );

            Document document = parser.parse(uri);
            counter.traverse(document);
            long after = System.currentTimeMillis();
            counter.printResults(uri, after - before);
        } catch (org.xml.sax.SAXParseException spe) {

so in DOM case you measure Document tree creation (parser.parse(uri)) _and_ traversing
(counter.traverse(document);)


        try {
            SAXBuilder builder = new SAXBuilder();
            Document document = builder.build(uri);
            JDOMCount counter = new JDOMCount();
            long before = System.currentTimeMillis();

            counter.traverse(document.getRootElement());
            long after = System.currentTimeMillis();
            counter.printResults(uri, after - before);
        } catch (Exception e) {
            e.printStackTrace(System.err);
        }

however for JDOM you have excluded Document tree creation from time measuring (Document document
= builder.build(uri)) and only included (counter.traverse(document.getRootElement());).

so i would say walking _already_ constructed tree of 4 elements should be pretty fast (and i
guess as well for DOM...).

thanks,

alek
--
Aleksander Slominski, LH 316, IU, http://www.extreme.indiana.edu/~aslom
As I look afar I see neither cherry Nor tinted leaves Just a modest hut
on the coast In the dusk of Autumn nightfall - Fujiwara no Teika (1162-1241)