QSA perf in IE

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
GetElementsByClassName
function getElementsByClassName(oElm, strTagName, strClassName) {
  var arrElements = (strTagName == "*" && oElm.all) ? oElm.all : oElm.getElementsByTagName(strTagName);
  var arrReturnElements = new Array();
  strClassName = strClassName.replace(/\-/g, "\\-");
  var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
  var oElement;
  for (var i = 0; i < arrElements.length; i++) {
    oElement = arrElements[i];
    if (oRegExp.test(oElement.className)) {
      arrReturnElements.push(oElement);
    }
  }
  return (arrReturnElements)
}

window.SELECT = function(str) {
  return getElementsByClassName(document.getElementsByTagName('html')[0], null, str);
}

window.SELECT("thediv");
pending…
LeRoy
// http://weblogs.asp.net/bleroy/archive/2009/08/31/queryselectorall-on-old-ie-versions-something-that-doesn-t-work.aspx
(function() {
  var style = document.styleSheets[0] || document.createStyleSheet();
  window.SELECT = function(selector) {
    style.addRule(selector, "foo:bar");
    var all = document.all,
        resultSet = [];
    for (var i = 0, l = all.length; i < l; i++) {
      if (all[i].currentStyle.foo === "bar") {
        resultSet[resultSet.length] = all[i];
      }
    }
    style.removeRule(0);
    return resultSet;
  }
})();

window.SELECT('body > div > div > div[class="thediv"] > span');
pending…
Ajaxian Person
window.SELECT = function(selector) {
  var head = document.documentElement.firstChild;
  var styleTag = document.createElement("STYLE");
  head.appendChild(styleTag);
  document.__qsResult = [];

  styleTag.styleSheet.cssText = selector + "{zoom:expression(this.runtimeStyle.zoom='1',document.__qsResult.push(this))}";
  window.scrollBy(0, 0);
  head.removeChild(styleTag);

  var result = [];
  for (var i in document.__qsResult)
  result.push(document.__qsResult[i]);
  return result;
}

window.SELECT('body > div > div > div[class="thediv"] > span');
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