Variable outside faster (v6)

Revision 6 of this benchmark created by amrutha on


Description

Check whether declaring a variable outside or inside a loop is faster.

Preparation HTML

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<div class=copy></div><div class=copy></div><div class=copy></div>
<div class=copy></div><div class=copy></div><div class=copy></div>
<div class=copy></div><div class=copy></div><div class=copy></div>
<div class=copy></div><div class=copy></div><div class=copy></div>

Test runner

Ready to run.

Testing in
TestOps/sec
inside
$('.copy').each(function() {
  var i = $(this).clone().removeClass('copy');

});
ready
outside
var i = null;
$('.copy').each(function() {
  i = $(this).clone().removeClass('copy');

});
ready

Revisions

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