using id selector with or without cached scope

Benchmark created on


Preparation HTML

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js">
</script>
<div><div><div><div><div><div><div>
<div><div><div><div><div><div><div>
  <div id="container">
    <div>
    </div>
    <div>
    </div>
    <div class="robotarm">
    </div>
    <div>
      <div id="robotarm">
      </div>
    </div>
    <div class="robotarm">
    </div>
    <div class="robotarm">
    </div>
    <div>
    </div>
  </div>
</div>
</div></div></div></div></div></div></div>
</div></div></div></div></div></div></div>

<div><div><div><div><div><div><div>
</div></div></div></div></div></div></div>
<div><div><div><div><div><div><div>
</div></div></div></div></div></div></div>
<div><div><div><div><div><div><div>
</div></div></div></div></div></div></div>
<div><div><div><div><div><div><div>
</div></div></div></div></div></div></div>

Setup

function cached() {
      $div = $('#container');
      for (i = 0; i < 1000; i++){
        $div.find('#robot-arm').html('foo');
      }
    }
    
    function raw() {
      for (i = 0; i < 1000; i++){
        $('#robot-arm').html('foo');
      }
    }

Test runner

Ready to run.

Testing in
TestOps/sec
restrict scope to cached parent
cached()
ready
do not restrict scope
raw()
ready

Revisions

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