For Of Loop Performance

Benchmark created on


Preparation HTML

<script>
    var sampleData = [];
    for (var i = 0; i < 10000; i++) {
        sampleData[i] = i;
    }

    function modifyData(value) {
        return (value * 5) / 2;
    }
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
For (Non-Cached Length)
for (var i = 0; i < arr.length; i++) {
    modifyData(arr[i]);
}
ready
For (Cached Length)
for (var i = 0, n = arr.length; i < n; i++) {
    modifyData(arr[i]);
}
ready
For...of
for (var val in arr) {
    modifyData(val);
}
ready

Revisions

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