Selectors

JavaScript performance comparison

Revision 5 of this test case created by notApplicable

Preparation code

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
<p>
  <span class="findMe">
    Span
    <span>
</p>
<p>
  <span class="findMe">
    Span
    <span>
</p>
<p>
  <span class="findMe">
    Span
    <span>
</p>
<p>
  <span class="findYou">
    Span
    <span>
</p>
<p>
  <span class="findMe">
    Span
    <span>
</p>
<p>
  <span class="findYou">
    Span
    <span>
</p>
<p>
  <span class="findMe">
    Span
    <span>
</p>
      
<script>
Benchmark.prototype.setup = function() {
  var els = new Array();

};
</script>

Preparation code output

<p> <span class="findMe"> Span <span> </p> <p> <span class="findMe"> Span <span> </p> <p> <span class="findMe"> Span <span> </p> <p> <span class="findYou"> Span <span> </p> <p> <span class="findMe"> Span <span> </p> <p> <span class="findYou"> Span <span> </p> <p> <span class="findMe"> Span <span> </p>

Test runner

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

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
JQ
els = $('.findMe');
els.css('color', 'red');
els.hide();
els.show();
els.append('<p>Test</p>');
els.children(':last-child').remove();
pending…
Raw
els = document.getElementsByClassName('findMe');
var p,len = els.length;
for (var i = 0; i < len; i++) {
  els[i].style.color = 'red';
}
for (var i = 0; i < len; i++) {
  els[i].style.display = 'none';
}
for (var i = 0; i < len; i++) {
  els[i].style.display = 'inline';
}
for (var i = 0; i < len; i++) {
  p = document.createElement('p');
  p.appendChild(document.createTextNode('Test'));
  els[i].appendChild(p);
}
for (var i = 0; i < len; i++) {
  els[i].removeChild(els[i].lastChild);
}
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.

0 Comments

Span

Span

Span

Span

Span

Span

Span