XPath vs. querySelectorAll with IE polyfill (v10)

Revision 10 of this benchmark created on


Preparation HTML

<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>

Test runner

Ready to run.

Testing in
TestOps/sec
XPath 1
if (document.evaluate) {
  document.evaluate('./div/div/div[@class="thediv"]/span', document.body, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
}
ready
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');
ready
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');
ready
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');
ready
XPath 2
if (document.evaluate) {
  document.evaluate('./div/div/div[@class="thediv"]/span', document.body, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
}
ready
XPath 3
if (document.evaluate) {
  document.evaluate('./body/div/div/div[@class="thediv"]/span', document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
}
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.