dagblog.
← Archive

Java XML processing: SAX versus DOM read performance


Tomáš Kouba compared SAX and DOM read performance for an XML document
on the .NET platform. I was curious, so I asked Tomáš for the source and test
XML files and rewrote his test in Java.

The results were hardly surprising. As the XML file got larger, the performance gap
widened in favor of SAX. For a local file with 10,000 nodes, SAX was about three times
as fast.

Node countDOM local(ms)DOM remote(ms)SAX local(ms)SAX remote(ms)
100233273153203
1000517828270571
10000222352177373688

I measured the values above on Windows 2000 with JRE 1.4.2-b28
(standard JAXP).

In practice, the object structure that DOM provides is much
easier to work with. If XML processing speed is secondary, I recommend DOM.
This benchmark was never intended to compare SAX and DOM on .NET against their Java counterparts. Two differences come to mind.
The .NET XML parser ignores whitespace, while the Java parser keeps it
by default.

For further investigation I would try an XML document with a more complex structure
and, on the Java side, newer versions of Xalan (Xerces) or
other XML parsers.

Medium version · Archived original page

Related articles

Related CZ Podcast episodes