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:136.0) Gecko/20100101 Firefox/136.0
Browser:
Firefox 136
Operating system:
Windows
Device Platform:
Desktop
Date tested:
one year ago
Benchmark engine:
Benchmark.js
for i--
2.5M/s
for i++
2.0M/s
while i--
1.1M/s
forEach
390K/s
for of
181K/s
View exact numbers
Test name
Executions per second
✓
for i--
2,451,815 Ops/sec
for i++
1,957,416 Ops/sec
while i--
1,116,413 Ops/sec
forEach
390,382 Ops/sec
for of
181,396 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 })