[jdom-interest] JDOM comparison with DOM

Dennis Sosnoski dms at sosnoski.com
Tue May 8 08:27:05 PDT 2001


Hi Abhishek,

Your test can't be counted on as accurate for the memory sizes, since it just does a snapshot
of the memory state after the construction of the documents. To do this more accurately, you
can request a garbage collection and then pause your main thread for a second or two to give
the best chance that the garbage collection will actually take place before you measure the
memory in use.

You should also measure the memory in use rather than the amount free, since the total amount
in use can change as the JVM allocates more memory from the system. Use:

  java.lang.Runtime.getRuntime().getTotalMemory() -
java.lang.Runtime.getRuntime().getFreeMemory()

to compute the amount of memory actually in use before and after building the document.

That said, I expect you'll find that DOM actually uses less memory than JDOM, as well as
being faster. This will hopefully improve as JDOM gets tuned, but there may always be a
tradeoff involved in getting the ease of use provided by the Collections interfaces in JDOM.

  - Dennis

abisheks wrote:

> Hello All,
>
> I wrote a simple Java program that can build a DOM object or a JDOM Object
> on a XML file of size 8 MB.
>
> I found that the time taken to build a DOM object is lesser that the time
> taken to build a JDOM Object.
> But the memory utilized by JDOM is far less than DOM.
>
> However, the documentation of JDOM suggested that the JDOM operates faster
> than DOM ( at par with SAX ).
>
> Why am I getting results that are different from what the JDOM documentation
> sugguests ?
>
> Both the source and the binary of my application is attached with this mail.
>
> usage :
>
> to build DOM:
> java Compare <filename.xml> 1
>
> to build JDOM
> java Compare <filename.xml> 2
>
> Here are the results which I got
>
> C:\abhishek\app>java Compare test.xml 1
> inside compare
> Xml file to be parsed : test.xml
> inside build Dom
> Time taken to build Dom: 8212
> Memory used to build Dom: 11190984
>
> C:\abhishek\app>java Compare test.xml 2
> inside compare
> Xml file to be parsed : test.xml
> inside build JDom
> Time taken to build JDom: 15312
> Memory used to build JDom: 6084888
>
> regards,
> Abhishek.
>
>   --------------------------------------------------------------------------------
>                    Name: Compare.java
>    Compare.java    Type: unspecified type (application/octet-stream)
>                Encoding: quoted-printable
>
>                     Name: Compare.class
>    Compare.class    Type: CLASS File (application/x-unknown-content-type-class_auto_file)
>                 Encoding: base64




More information about the jdom-interest mailing list