This articles reports the measurement of XPath evaluation performance for VTD-XML version 2.0, and compares with Xerces 2.7.1 DOM and XPath functions bundled with JDK 1.6 (which is Xalan), as well as Jaxen 1.1.
The benchmark code performs the following steps:
All benchmark programs first loop thru the XPath evaluation code a number of iterations so the server JVM compile them into native code to obtain optimal performance, before the real measurement of the average latency of subsequent XPath evaluations.
Three XML files of similar structure, but different sizes, are used for the test.
<?xml version="1.0"?>
<purchaseOrder orderDate="1999-10-20">
<shipTo country="US">
<name>Alice Smith</name>
<street>123 Maple Street</street>
<city>Mill Valley</city>
<state>CA</state>
<zip>90952</zip>
</shipTo>
<billTo country="US">
<name> Robert Smith </name>
<street>8 Oak Avenue</street>
<city>Old Town</city>
<state>PA</state>
<zip>95819</zip>
</billTo>
<comment>Hurry, my lawn is going wild!</comment>
<items>
<item partNum="872-AA">
<productName>Lawnmower</productName>
<quantity></quantity>
<USPrice>148.95</USPrice>
<comment>Confirm this is electric</comment>
</item>
<item partNum="926-AA">
<productName>Baby Monitor</productName>
<quantity>1</quantity>
<USPrice>39.98</USPrice>
<shipDate>1999-05-21</shipDate>
</item>
...
</items>
</purchaseOrder>
The respective file sizes are:
The following XPath expressions are used for the test
DOM Code | Jaxen Code | VTD-XML Code |
Document d = null; k = total; d = parser.parse(bais); while (k > 0) { NodeList nodeList = (NodeList) xPathExpression.evaluate(d, XPathConstants.NODESET); k--; } long l=0,lt=0; for (int j = 0; j < 10; j++) { l = System.currentTimeMillis(); for (int i = 0; i < total; i++) { NodeList nodeList = (NodeList) xPathExpression.evaluate(d, XPathConstants.NODESET); } long l2 = System.currentTimeMillis(); lt = lt + (l2 - l); } System.out.println(" average XPath latency ==> " + ((double) (lt) / total / 10) + " ms");
|
XPath expression = new org.jaxen.dom.DOMXPath(xpe); System.out.println("====> update_jaxen1 ==>"+xpe); //parse and xpath eval Document d = null; d = parser.parse(bais); k = total; while (k > 0) { List results = expression.selectNodes(d); k--; } long l=0,lt=0; for (int j = 0; j < 10; j++) { l = System.currentTimeMillis(); for (int i = 0; i < total; i++) { List results = expression.selectNodes(d); } long l2 = System.currentTimeMillis(); lt = lt + (l2 - l); } System.out.println(" average XPath latency ==> " + ((double) (lt) / total / 10) + " ms");
|
k=total; VTDNav vn = null; while(k>0){ while((i1=ap.evalXPath())!=-1){ } ap.resetXPath(); k--; } for (int j=0;j<10;j++){ l = System.currentTimeMillis(); for(int i = 0;i<total;i++) { while((i1=ap.evalXPath())!=-1){ } ap.resetXPath(); } long l2 = System.currentTimeMillis(); lt = lt + (l2 - l); //System.out.println("j ==> "+j); } System.out.println(" average XPath latency ==> "+ ((double)(lt)/total/10) + " ms");
|
Notice that the table includes # of nodes returned from XPath evaluation.
/*/*/*[position() mod 2 = 0]
Jaxen (ms) | JDK (ms) | VTD-XML (ms) | |
po_small.xml | 0.0395 | 1.123 | 0.00994 |
po_medium.xml | 0.524 | 6.552 | 0.115 |
po_big.xml | 8.812 | 94.535 | 1.292 |
/purchaseOrder/items/item[USPrice <100]
Jaxen (ms) | JDK (ms) | VTD-XML (ms) | |
po_small.xml | 0.0857 | 1.204 | 0.048 |
po_medium.xml | 1.498 | 9.381 | 0.854 |
po_big.xml | 22.262 | 113.831 | 9.238 |
/*/*/*/quantity/text()
Jaxen (ms) | JDK (ms) | VTD-XML (ms) | |
po_small.xml | 0.107 | 1.0756 | 0.0317 |
po_medium.xml | 1.922 | 7.0268 | 0.537 |
po_big.xml | 32.181 | 106.7 | 6.339 |
//item/comment
Jaxen (ms) | JDK (ms) | VTD-XML (ms) | |
po_small.xml | 0.356 | 1.208 | 0.089 |
po_medium.xml | 9.824 | 9.922 | 1.505 |
po_big.xml | 197.319 | 138.45 | 17.825 |
//item/comment/../quantity
Jaxen (ms) | JDK (ms) | VTD-XML (ms) | |
po_small.xml | 0.374 | 1.274 | 0.105 |
po_medium.xml | 11.147 | 10.298 | 1.787 |
po_big.xml | 204.714 | 140.06 | 21.06 |
/*/*/*/* [position() mod 2 = 0]
Jaxen (ms) | JDK(ms) | VTD-XML(ms) | |
po_small.xml | 0.136 | 1.21 | 0.0353 |
po_medium.xml | 2.7 | 8.216 | 0.604 |
po_big.xml | 65.469 | 122.83 | 6.559 |
/purchaseOrder/items/item[USPrice > 100]/comment/text()
Jaxen (ms) | JDK (ms) | VTD-XML (ms) | |
po_small.xml | 0.113 | 1.262 | 0.06 |
po_medium.xml | 2.082 | 9.154 | 1.061 |
po_big.xml | 32.892 | 121.07 | 12.35 |
/*/*/*[position() mod 2 = 0]
/purchaseOrder/items/item[USPrice <100]
/*/*/*/quantity/text()
//item/comment
//item/comment/../quantity
/*/*/*/* [position() mod 2 = 0]
/purchaseOrder/items/item[USPrice > 100]/comment/text()