|
From: Kalle A. <kal...@gm...> - 2013-08-23 15:03:46
|
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 & caching, what is the best
way to do this? Will I need a new AutoPilot instance per XPath expression?
Thanks for your help,
/Kalle
On 23 August 2013 00:37, <jz...@xi...> wrote:
>
> 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 <kal...@gm...>
>
> To:
> <vtd...@li...>
> 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 DOM
> End DOM
> Time Taken : 3023.547643
>
>
> Start VTD
> End VTD
> Time 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 & VTD-XML version 2.11
>
> Thanks,
>
> /Kalle
>
>
> === BEGIN TEST XML FILE ===
>
> <?xml version="1.0" encoding="utf-8"?>
> <TestLevel1>
> <TestLevel2>
> <TestLevel3 attr="test"></TestLevel3>
> </TestLevel2>
> </TestLevel1>
>
> === END TEST XML FILE ===
>
>
>
> === BEGIN SOURCE CODE ===
>
> import com.ximpleware.AutoPilot;
> 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 org.xml.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"); <http://test.xml>
> 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<String> 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<String> {
>
> 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<String> {
>
> 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 ===
>
>
|