[jdom-interest] Speed!? JDOM vs DOM

Gary Bentley gb at opengroup.org
Wed Mar 7 03:56:14 PST 2001


As promised here is some very simple code that lets you see how long it
takes to parse the
XML and generate the JDOM Document object.

Please note the following:

    JDOM 6 is used
    Validation if OFF
    Crimson with JAXP is the parser

I've tried out the examples...I eat the cakes I bake...and some results are
given below:

For both examples 1000 iterations were used for the average parse time.

For a fairly simple custom XML file, size 15K

    Windows 2000, Java 1.2.2, 300MHz, 128MB ram
	  Time for first parse: ~1200 milliseconds
	  Average parse time  : 28 milliseconds

    Solaris 7, Java 1.2.2, not sure about rest of spec
        Time for first parse: ~1400 milliseconds
        Average parse time  : 76 milliseconds

Please note that the Solaris box is multi-user and quite heavily loaded.

For an XHTML file, size 41K, note there is a DOCTYPE line which may mean the
parser is also trying to get the
DTD but this may not be true not sure how it works with validation off

    Windows 2000, Java 1.2.2, 300MHz, 128MB ram
        Time for first parse: ~1600 milliseconds
        Average parse time  : 129 milliseconds

    Solaris 7, Java 1.2.2, not sure about rest of spec
        Time for first parse: ~1900 milliseconds
        Average parse time  : 417 milliseconds

Of course take these measurements with a pinch of salt but the bottom line
is that
I've found JDOM with Crimson very fast and certainly fast enough for the
applications
that I use.

I have a pre-built Jar file that can be used if anyone wants to try.

To use just pass an XML file on the command line...

Code below>>>

import java.io.*;
import java.util.*;
import org.jdom.*;
import org.jdom.input.*;

public class XMLTest
{

    public XMLTest (String xmlfile)
                    throws Exception
    {

	for (int i = 0; i < 100; i++)
	{

	    File file = new File (xmlfile);
	    BufferedInputStream bin = new BufferedInputStream (new FileInputStream
(file));

	    long start = System.currentTimeMillis ();

	    Document doc = (new SAXBuilder ().build (bin));

	    long end = System.currentTimeMillis ();

	    doc = null;

	    System.out.println ("Iteration: " + i);
	    System.out.println ("   Start time: " + start);
	    System.out.println ("   End time  : " + end);
	    System.out.println ("   Parse time: " + (end - start));
	    System.out.println ("   File size : " + file.length ());

	}

	long start = System.currentTimeMillis ();

	for (int i = 0; i < 1000; i++)
	{

	    File file = new File (xmlfile);
	    BufferedInputStream bin = new BufferedInputStream (new FileInputStream
(file));

	    Document doc = (new SAXBuilder ().build (bin));
	    doc = null;

	}

	long end = System.currentTimeMillis ();

	System.out.println ("Average time for 1000 iterations: " + ((end - start) /
1000));



    }

    static public void main (String argv[])
    {

	try
	{

	    new XMLTest (argv[0]);

	} catch (Exception e) {

	    e.printStackTrace (System.out);

	}

    }

}

End code>>>

-----Original Message-----
From: jdom-interest-admin at jdom.org
[mailto:jdom-interest-admin at jdom.org]On Behalf Of Cameron Smith
Sent: Tuesday, March 06, 2001 4:35 PM
To: 'jdom-interest at jdom.org'
Cc: 'rolf at smb-tec.com'
Subject: [jdom-interest] Speed!? JDOM vs DOM


Rolf, your performance comparison is interesting.  However unless you run
the test enough times to stabilise results (so that random factors and VM
setup costs don't affect them) the results aren't that meaningful.  When
benchmarking JDom versus an in-house parser I found that results only
stabilised at 100k - 150k test cycles.  Admittedly this was with a much
shorter XML document (about 100 lines) but even given this you would perhaps
need to run at least 1000 cycles.

Secondly, I think the performance argument can be overstated when discussing
XML libraries.  The biggest advantage of JDom versus DOM is the usability of
its API.  The DOM interfaces are ugly and lead to extra programmer resource
spent on writing utility code to make them more user-friendly (but for all
that, they are still a de facto standard, and thus wonderful!). Therefore if
you are really concerned about performance you can spend some of the
man-hour savings on chunkier hardware.

Finally, you need to consider what proportion of your total processing time
will be spent parsing/generating XML.  For my applications, 'XML time' is a
fairly small fraction of total transaction time (which includes several
other costly tasks including network and database transactions).  Therefore
the speed of parsers is not that important.
On the other hand, from the looks of it you are dealing with pretty large
documents so 'XML time' could be a much bigger part of your total processing
time.

cameron

	Cameron Smith, Software Developer
	Entranet Ltd

	Email:   cameron.smith at entranet.co.uk
	Tel:      44 (0) 131 247 7400
Fax:      44 (0) 131 247 7404


----------------------------------------------------------------------------
---------------------------------
	The information contained in this email and any attachment is
intended for and confidential to the addressee(s) only.

	If you have received this information in error and you are neither
the addressee nor an authorised recipient of the addressee, please notify
Entranet on 01491 878785 immediately and delete the email from your system.
Please note the information contained in, or attached to this email must not
be used, copied, or disseminated in any way.

	Unless approved literature of Entranet is included, any views or
opinions expressed are those of the sender and do not necessarily represent
those of Entranet.

	Please note Entranet accepts no liability for any viruses, which may
be transmitted in or with this email, nor does it accept responsibility for
any such data corruption, interception or unauthorised amendment which can
occur as a result of internet/email communications.


	Entranet - creators of online commerce
	<http://www.entranet.co.uk/>

	Entranet Limited
	Registered office - 4 Thames Court, Goring-On-Thames, Reading RG8
9AQ
	Registered in England No. 3267855

----------------------------------------------------------------------------
---------------------------------

_______________________________________________
To control your jdom-interest membership:
http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhos
t.com




More information about the jdom-interest mailing list