|
From: <jz...@xi...> - 2013-08-23 20:18:15
|
To reuse xpath, all you need to do is keep AutoPilot object alive
after selecting xpath, you also need to call resetXPath(),
AutoPilot's internal caching is not for XPath compilation, it is
designed for speeding up repetitive xpath evaluation when the xpath is
absolute andresides within a predicate...
I can't tell for sure why there is no difference is performance (i
would have guessed that there is a huge difference), it might have to
do with your xpath expression evaluating to a string... try to
evaluate to a node set to see if you see any difference....
----- Original Message -----
From: Kalle Anka
To:
Cc:
Sent:Fri, 23 Aug 2013 16:03:38 +0100
Subject:Re: [Vtd-xml-users] XPath evaluation 3x-4x slower than JDK
with DOM?
Thanks for the quick reply.
I replaced my test XML file with a "real" one from my application
domain (~25MB in size) and inserted the test XML tags into middle of
it. I re-ran the test but there was virtually no difference in
performance using either evaluator.
I attached a debugger and confirmed what you suggested, that the
XPath compilation is by far the biggest contributor to the total time.
I cached the XPath compilation and got much better results.
I expected the AutoPilot object to do this caching already because
there is a method called enableCaching() which is by default enabled.
What is it caching if not the compiled XPath expression? I will
have 100's-1000's of XPath expressions that would need compilation
border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex;">
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 external packages, 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 VTD End 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
import com.ximpleware.NavException;import
com.ximpleware.VTDGen;import com.ximpleware.VTDNav;import
com.ximpleware.XPathParseException;
import java.io.File; import java.io.IOException;import
java.util.concurrent.Callable;import
javax.xml.parsers.DocumentBuilderFactory;import
javax.xml.parsers.ParserConfigurationException; import
javax.xml.xpath.XPath; import javax.xml.xpath.XPathConstants;import
javax.xml.xpath.XPathExpression;import
javax.xml.xpath.XPathExpressionException;import
javax.xml.xpath.XPathFactory;
import org.w3c.dom.Document;import org.w3c.dom.Node;import
orgxml.sax.SAXException;
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"); [4] 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(); System.out.println("Start "
+ name); long startTime = System.nanoTime(); try
{ for (int i = 0; i < 1000000; i++) {
String output = callable.call(); if
(!"TestLevel3"equals(output)) {
System.out.println("Failed: " + output);
break; } } }
catch (Exception exception) {
System.out.println(exception); } long endTime =
System.nanoTime(); double difference = (endTime -
startTime)/1e6; System.out.println("End " + name);
System.out.println("Time Taken : " + difference);
System.out.println(); }
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);
fXPath =
XPathFactory.newInstance().newXPath();
XPathExpression expression =
fXPath.compile(NODE_SELECTION_EXPRESSION);
fNode = (Node)expression.evaluate(document, XPathConstants.NODE);
} catch (ParserConfigurationException | SAXException |
IOException | XPathExpressionException exception) {
throw new RuntimeException(exception); }
}
@Override public String call() {
try { XPathExpression expression =
fXPath.compile(GET_NAME_EXPRESSION); return
(String)expression.evaluate(fNode, XPathConstants.STRING);
} 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(), false); VTDNav
vn = vg.getNav(); fAutoPilot = new AutoPilot(vn);
try {
fAutoPilot.selectElement(NODE_SELECTION_EXPRESSION);
fAutoPilot.iterate(); } catch (NavException
exception) { throw new
RuntimeException(exception); } }
@Override public String call() {
try {
fAutoPilot.selectXPath(GET_NAME_EXPRESSION);
return fAutoPilot.evalXPathToString(); } catch
(XPathParseException e) { throw new
RuntimeException(e); } }
}
}
=== END SOURCE CODE ===
Links:
------
[1] mailto:jz...@xi...
[2] mailto:kal...@gm...
[3] mailto:vtd...@li...
[4] http://test.xml
|