Variable outside faster (v9)

Revision 9 of this benchmark created 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');
   $('body').append( i );
});
 
ready
outside
var i;
$('.copy').each( function() {
   i = $(this).clone().removeClass('copy');
   $('body').append( i );
});
ready

Revisions

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