let vs var performance

JavaScript performance comparison

Revision 9 of this test case created by Yazan Medanat

Preparation code

<script>
  var firstarray = [];
  for (var i = 0; i < 1000; i++) {
    firstarray[i] = Math.floor(Math.random() * 11);
  }
  var secondarray = [];
  for (var i = 0; i < 1000; i++) {
    secondarray[i] = Math.floor(Math.random() * 11);
  }
</script>
<script>
Benchmark.prototype.setup = function() {
      var firstarray = [];
      for (var i = 0; i < 1000; i++) {
        firstarray[i] = Math.floor(Math.random() * 11);
      }
      var secondarray = [];
      for (var i = 0; i < 1000; i++) {
        secondarray[i] = Math.floor(Math.random() * 11);
      }
};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
var
var resultarray = [];
for (var i = 0; i < 1000; i++) {
  var firstnumber = firstarray[i];
  var secondnumber = secondarray[i] + 5;
  var total = firstnumber + secondnumber
  resultarray.push(total);
}
pending…
let
var resultarray = [];
for (var i = 0; i < 1000; i++) {
  let firstnumber = firstarray[i];
  let secondnumber = secondarray[i] + 5;
  let total = firstnumber + secondnumber
  resultarray.push(total);
}
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. Here’s a list of current revisions for this page:

0 comments

Add a comment