XPath vs. querySelectorAll

JavaScript performance comparison

Revision 2 of this test case created

Preparation code

<div class='adiv'>
  test text inside a div!
</div>
<div class='adiv'>
  test text inside a div!
</div>
<div>
  <div>
    <div class='thediv'>
      test test test test test test
      <span>
        this is a span
      </span>
    </div>
  </div>
</div>
<div class='adiv'>
  test text inside a div!
</div>
<div class='adiv'>
  test text inside a div!
</div>
<div class='adiv'>
  test text inside a div!
</div>

Preparation code output

test text inside a div!
test text inside a div!
test test test test test test this is a span
test text inside a div!
test text inside a div!
test text inside a div!

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
XPath 1
document.evaluate('./div/div/div[@class="thediv"]/span', document.body, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
pending…
querySelectorAll 1
document.querySelectorAll('body > div > div > div[class="thediv"] > span');
pending…
querySelectorAll 2
document.querySelectorAll('body > div > div > div.thediv > span');
pending…
querySelectorAll 3
document.body.querySelectorAll('div > div > div[class="thediv"] > span');
pending…
XPath 2
document.evaluate('./div/div/div[@class="thediv"]/span', document.body, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
 
pending…
XPath 3
document.evaluate('/body/div/div/div[@class="thediv"]/span', document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

0 comments

Add a comment