Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
while vs for vs forEach vs for of - 1000000 - calc
Compare the new ES6 spread operator with the traditional concat() method and push
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/126.0.0.0 Safari/537.36
Browser:
Chrome 126
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
while
743.7 Ops/sec
for
746.4 Ops/sec
forEach
63141.4 Ops/sec
for of
239631.1 Ops/sec
Script Preparation code:
var arr =new Array(10000);
Tests:
while
let i=0; while(i < arr.length) { const exp = arr[i] ** 2; i++; }
for
for(let i=0; i<arr.length; i++) { const exp = arr[i] ** 2; }
forEach
arr.forEach((element) => { const exp = element ** 2; });
for of
for(const element of arr) { const exp = element ** 2; }