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 count | DOM local(ms) | DOM remote(ms) | SAX local(ms) | SAX remote(ms) |
|---|---|---|---|---|
| 100 | 233 | 273 | 153 | 203 |
| 1000 | 517 | 828 | 270 | 571 |
| 10000 | 2223 | 5217 | 737 | 3688 |
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
- #3 · Java 6 SE, Vývoj webových aplikací
Dagi and Filemon discuss Java 6 and web application frameworks. · Czech audio
- #1 · Vývojová prostředí v Javě
The first CZ Podcast episode looks at Java development environments. · Czech audio