|
From: <jz...@xi...> - 2013-08-22 23:38:00
|
Hi, The xml files you run tests are very very small. At those sizes,
the performance number you are getting from vtd-xml wll be dominated
by the performance of compile xpath expression, which is done by using
java cup and jflex, both externalpackages, so they are not good way
measure the performance of parsing and xpath evaluation... in reality,
those xpath compilations can be done once and reused many many times,
so even with some overhead, this can be easily optimized away
I am sure if you increase teh size of xml to a few k or MB in size,
or reuse xpath, you will see a dramatically improvement of
performance...
----- Original Message -----
From: Kalle Anka
To:
Cc:
Sent:Thu, 22 Aug 2013 15:46:50 +0100
Subject:[Vtd-xml-users] XPath evaluation 3x-4x slower than JDK with
DOM?
Hello,
I'm trying to evaluate the performance of vtd for my application
after perusing the benchmark results published on the main page.
However, I'm seeing quite a substantial difference in performance of
XPath evaluation between vtd and the standard DOM/JDK implementation.
My simple test evaluates a simple XPath expression ("name()") from
the context of a specific tag one million times in a row and these are
the results I am seeing (in ms):
Start DOMEnd DOMTime Taken : 3023.547643
Start VTDEnd VTDTime Taken : 10416.065461
My DOM implementation consistently outperforms the vtd 3x-4x. Am I
doing something wrong? I would be grateful for any feedback.
Note1: I've included the full code of my test at the end of this
e-mail. Note2: I've used the same XPath expression in each iteration
for testing purposes only, in reality there will be 1000's of
different expressions.
Note3: I'm using Java 7 [1]
import com.ximpleware.NavException; [2]import com.ximpleware.VTDGen;
[3]import com.ximpleware.VTDNav; [4]import
com.ximpleware.XPathParseException; [5]
import java.io.File; [6] import java.io.IOException; [7]import
java.util.concurrent.Callable; [8]import
javax.xml.parsers.DocumentBuilderFactory; [9]import
javax.xmlparsers.ParserConfigurationException; [10]import
javax.xml.xpath.XPath; [11] import javax.xml.xpath.XPathConstants;
[12]import javax.xml.xpath.XPathExpression; [13]import
javax.xml.xpath.XPathExpressionException; [14]import
javax.xml.xpath.XPathFactory; [15]
import org.w3c.dom.Document; [16]import org.w3c.dom.Node; [17]import
org.xml.sax.SAXException; [18]
public class XPathTest {
private static final String NODE_SELECTION_EXPRESSION =
"//TestLevel3"; private static final String GET_NAME_EXPRESSION
= "name()";
private XPathTest() {}
public static void main(String[] args) { File file
= new File("xpath_test.xml"); [19] runXPathDomTest(file);
runXPathVtdTest(file); }
private static void runXPathDomTest(File file) {
runTest(new DomCallable(file), "DOM"); }
private static void runXPathVtdTest(File file) {
runTest(new VtdCallable(file), "VTD"); }
private static void runTest(Callable callable, String name) {
System.out.println(); [20]
System.out.println("Start [21] " + name); long startTime =
System.nanoTime(); [22] try { for (int i =
0; i < 1000000; i++) { String output =
callable.call(); [23] if
(!"TestLevel3".equals(output)) {
System.out.println("Failed: [24] " + output);
break; } } }
catch (Exception exception) {
System.out.println(exception); [25] } long
endTime = System.nanoTime(); [26] double difference =
(endTime - startTime)/1e6; System.out.println("End [27]
" + name); System.out.println("Time [28] Taken : " +
difference); System.out.println(); [29] }
private static class DomCallable implements Callable {
private final File fFile; private final Node
fNode; private final XPath fXPath;
private DomCallable(File file) { fFile =
file; try { Document document
=
DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(file);
[30] fXPath =
XPathFactory.newInstance().newXPath(); [31]
XPathExpression expression =
fXPath.compile(NODE_SELECTION_EXPRESSION); [32]
fNode = (Node)expression.evaluate(document [33], XPathConstants.NODE);
[34] } catch (ParserConfigurationException |
SAXException | IOException | XPathExpressionException exception) {
throw new RuntimeException(exception);
} }
@Override public String call() {
try { XPathExpression expression =
fXPath.compile(GET_NAME_EXPRESSION); [35]
return (String)expression.evaluate(fNode [36], XPathConstants.STRING);
[37] } catch (XPathExpressionException e) {
throw new RuntimeException(e); }
}
}
private static class VtdCallable implements Callable {
private final File fFile; private final
AutoPilot fAutoPilot;
private VtdCallable(File file) { fFile =
file; VTDGen vg = new VTDGen();
vg.parseFile(fFile.getAbsolutePath() [38], false);
VTDNav vn = vg.getNav(); [39] fAutoPilot = new
AutoPilot(vn); try {
fAutoPilot.selectElement(NODE_SELECTION_EXPRESSION); [40]
fAutoPilot.iterate(); [41] } catch
(NavException exception) { throw new
RuntimeException(exception); } }
@Override public String call() {
try {
fAutoPilot.selectXPath(GET_NAME_EXPRESSION); [42]
return fAutoPilot.evalXPathToString(); [43] }
catch (XPathParseException e) { throw new
RuntimeException(e); } }
}
}
=== END SOURCE CODE ===
Links:
------
[1] http://sitemail.hostway.com/http:
[2] http://sitemail.hostway.com/http:
[3] http://sitemail.hostway.com/http:
[4] http://sitemail.hostway.com/http:
[5] http://sitemail.hostway.com/http:
[6] http://sitemail.hostway.com/http:
[7] http://sitemail.hostway.com/http:
[8] http://sitemail.hostway.com/http:
[9] http://sitemail.hostway.com/http:
[10] http://sitemail.hostway.com/http:
[11] http://sitemail.hostway.com/http:
[12] http://sitemail.hostway.com/http:
[13] http://sitemail.hostway.com/http:
[14] http://sitemail.hostway.com/http:
[15] http://sitemail.hostway.com/http:
[16] http://sitemail.hostway.com/http:
[17] http://sitemail.hostway.com/http:
[18] http://sitemail.hostway.com/http:
[19] http://test.xml
[20] http://sitemail.hostway.com/http:
[21] http://sitemail.hostway.com/http:
[22] http://sitemail.hostway.com/http:
[23] http://sitemail.hostway.com/http:
[24] http://sitemail.hostway.com/http:
[25] http://sitemail.hostway.com/http:
[26] http://sitemail.hostway.com/http:
[27] http://sitemail.hostway.com/http:
[28] http://sitemail.hostway.com/http:
[29] http://sitemail.hostway.com/http:
[30] http://sitemail.hostway.com/http:
[31] http://sitemail.hostway.com/http:
[32] http://sitemail.hostway.com/http:
[33] http://sitemail.hostway.com/http:
[34] http://sitemail.hostway.com/http:
[35] http://sitemail.hostway.com/http:
[36] http://sitemail.hostway.com/http:
[37] http://sitemail.hostway.com/http:
[38] http://sitemail.hostway.com/http:
[39] http://sitemail.hostway.com/http:
[40] http://sitemail.hostway.com/http:
[41] http://sitemail.hostway.com/http:
[42] http://sitemail.hostway.com/http:
[43] http://sitemail.hostway.com/http:
|