let vs var performance

JavaScript performance comparison

Revision 8 of this test case created

Preparation code

<script>
        var firstArray = [],
                secondArray = [],
                resultArray = [];

        for (var i = 0; i < 1000; i++) {
                firstArray[i] = Math.floor(Math.random() * 11);
                secondArray[i] = Math.floor(Math.random() * 11);
        }

        function runVarTest() {
    "use strict";              
                var firstNumber = secondNumber = 0;
                resultArray = [];
                for (var i = 0; i < 1000; i++) {
                        firstNumber = firstArray[i];
                        secondNumber = (secondArray[i] + 5);
                        resultArray.push(firstNumber + secondNumber);
                }
                return resultArray;
        }

        function runLetTest() {
    "use strict";
                let firstNumber = secondNumber = 0;
                resultArray = [];
                for (var i = 0; i < 1000; i++) {
                        firstNumber = firstArray[i];
                        secondNumber = (secondArray[i] + 5);
                        resultArray.push(firstNumber + secondNumber);
                }
                return resultArray;
        }
</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
let
runLetTest();
pending…
var
runVarTest();
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