Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
forloop performance test
save length of the array in the variable vs get it the loop
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Safari/537.36
Browser:
Chrome 141
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
7 months ago
Test name
Executions per second
for ... .length
422569.8 Ops/sec
for ... of
1238154.4 Ops/sec
for ... .length (cached)
436043.9 Ops/sec
for ... entries
470132.2 Ops/sec
Script Preparation code:
var arr = []; const count = 1000; for(let i = 0; i<count; i++) { arr.push(i); }
Tests:
for ... .length
let sum = 0; for (let i = 0; i < arr.length; i++){ sum += arr[i]; } if (sum !== 499500) throw 42;
for ... of
let sum = 0; let i = 0; for (let v of arr) { sum += v; ++i; } if (sum !== 499500) throw 42;
for ... .length (cached)
let sum = 0; for (let i = 0, l = arr.length; i < l; ++i){ sum += arr[i]; } if (sum !== 499500) throw 42;
for ... entries
let sum = 0; for (let [i,v] of arr.entries()) { sum += v; } if (sum !== 499500) throw 42;