Variable outside faster (v7)

Revision 7 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 id="container"></div>

Test runner

Ready to run.

Testing in
TestOps/sec
inside
    for (var i = 0; i < 10; i++) {
      var container = document.getElementById('container');
      container.innerHtml += 'my number: ' + i;
      console.log(i);
    }
ready
outside
    var container = document.getElementById('container');
    for (var i = 0, len = 10; i < len; i++) {
      container.innerHtml += 'my number: ' + i;
      console.log(i);
    }
ready

Revisions

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