XPath vs. querySelectorAll with IE polyfill

JavaScript performance comparison

Revision 10 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
if (document.evaluate) {
  document.evaluate('./div/div/div[@class="thediv"]/span', document.body, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
}
pending…
querySelectorAll 1
// https://gist.github.com/connrs/2724353
document.querySelectorAll||(document.querySelectorAll=function(a){var b=document,c=b.documentElement.firstChild,d=b.createElement("STYLE");return c.appendChild(d),b.__qsaels=[],d.styleSheet.cssText=a+"{x:expression(document.__qsaels.push(this))}",window.scrollBy(0,0),b.__qsaels});

document.querySelectorAll('body > div > div > div[class="thediv"] > span');
pending…
querySelectorAll 2
// https://gist.github.com/connrs/2724353
document.querySelectorAll||(document.querySelectorAll=function(a){var b=document,c=b.documentElement.firstChild,d=b.createElement("STYLE");return c.appendChild(d),b.__qsaels=[],d.styleSheet.cssText=a+"{x:expression(document.__qsaels.push(this))}",window.scrollBy(0,0),b.__qsaels});

document.querySelectorAll('body div div div[class="thediv"] > span');
pending…
querySelectorAll 3
// https://gist.github.com/connrs/2724353
document.querySelectorAll||(document.querySelectorAll=function(a){var b=document,c=b.documentElement.firstChild,d=b.createElement("STYLE");return c.appendChild(d),b.__qsaels=[],d.styleSheet.cssText=a+"{x:expression(document.__qsaels.push(this))}",window.scrollBy(0,0),b.__qsaels});

document.body.querySelectorAll('div > div > div[class="thediv"] > span');
pending…
XPath 2
if (document.evaluate) {
  document.evaluate('./div/div/div[@class="thediv"]/span', document.body, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
}
pending…
XPath 3
if (document.evaluate) {
  document.evaluate('./body/div/div/div[@class="thediv"]/span', document, null, XPathResult.ORDERED_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