Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
Feature Requests
FAQ
Register
Log In
Run results for:
for vs while vs for of vs forEach
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:138.0) Gecko/20100101 Firefox/138.0
Browser:
Firefox 138
Operating system:
Windows
Device Platform:
Desktop
Date tested:
one year ago
Benchmark engine:
Benchmark.js
for i--
2.3M/s
for i++
1.7M/s
while i--
1.2M/s
forEach
276K/s
for of
159K/s
View exact numbers
Test name
Executions per second
✓
for i--
2,348,879 Ops/sec
for i++
1,650,659 Ops/sec
while i--
1,216,660 Ops/sec
forEach
276,176 Ops/sec
for of
158,651 Ops/sec
Script Preparation code:
var arr = [] for (var i = 0; i < 1000; i++) arr[i] = i
Tests:
for i++
for (var i = 0; i < arr.length; i++) { var a = arr[i] }
for i--
for (var i = arr.length; i >= 0; i--) { var a = arr[i] }
while i--
var i = arr.length while (i--) { var a = arr[i] }
for of
for (var v of arr) { var a = v }
forEach
arr.forEach(v => { var a = v })