[jdom-interest] Performance: JDOM2 and Saxon
mike at saxonica.com
Mon Oct 24 05:29:22 PDT 2011
My colleague O'Neil Delpratt has been doing some performance experiments
with JDOM1 and JDOM2. Here are the results he is getting.
Experiment: I ran a somewhat simplified test harness on the same two
XPath expression (i.e. "//@null" and "//node()") on the XML document
Average time taken over 50 runs, excluding the first run.
Saxon (TinyTree treeModel): 2.8ms
Saxon (JDOM treeModel): 10.36ms
Saxon (JDOM2 treeModel): 10.82ms
The # of tree nodes:
Standalone JDOM(-2): 19840
The difference in results was down to whitespace between elements
represented as text nodes in JDOM(-2).
So: JDOM2 is doing a good job relative to JDOM1, but the XPath engine is
still very slow compared to Saxon's XPath engine.
The Saxon code for accessing JDOM2 uses the JDOM node.getDescendants()
method rather than making recursive use of getChildren() as we do with
JDOM1, and this benefits performance in that without this change, the
JDOM2 code ran in 12.28ms; but we're still getting slightly slower
results from JDOM2 despite this improvement.
I believe the way the measurements were done causes the XPath expression
to be compiled once and executed repeatedly.
The differences we are seeing from these results are:
(a) The TinyTree is very fast when processing the descendant axis
(because the nodes are held in an array in document order)
(b) In the scenario where XPath compile time is amortized over many
executions (the only case we've measured), the Saxon XPath engine is
much faster than the one built in to JDOM.
(c) JDOM2 is fractionally slower than JDOM1 in its navigational APIs,
even though its XPath engine is now three times faster.
More information about the jdom-interest