jquery find speed vs selector

JavaScript performance comparison

Revision 3 of this test case created by ac

Preparation code

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>

<div id="myDiv">
  <img src="#" />
</div>

<script>
for(var i = 0; i<5000; i++){
$('img').appendTo('#myDiv');
}
</script>
    

Preparation code output

<div id="myDiv"> <img src="#" /> </div> <script> for(var i = 0; i<5000; i++){ $('img').appendTo('#myDiv'); } </script>

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
find every element
$('body').find('#myDiv').find('img').addClass('test');
pending…
find
$('body').find('#myDiv img').addClass('test');
pending…
direct
$('#myDiv img').addClass('test');
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