a brief comparison of selection methods

JavaScript performance comparison

Test case created by David Thomas

Preparation code

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
<ul>
  <li>
    <div class="thumb">
      <img src="image-1.jpg">
    </div>
  </li>
  <li>
    <div class="thumb">
      <img src="image-2.jpg">
    </div>
  </li>
  <li>
    <div class="thumb selected">
      <img src="image-3.jpg">
    </div>
  </li>
</ul>

Preparation code output

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
$("div.selected img").attr("src")
$("div.selected img").attr("src")
pending…
$('img').filter(return $(this).closest('div.selected').length;).attr('src');
$('img').filter(function() {
  return $(this).closest('div.selected').length;
}).attr('src');
pending…

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

Compare results of other browsers

0 comments

Add a comment