Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
single for loop vs multiple for loops for iterating over arrays
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:133.0) Gecko/20100101 Firefox/133.0
Browser:
Firefox 133
Operating system:
Windows
Device Platform:
Desktop
Date tested:
one year ago
single loop (small N)
654K/s
separate loops (small N)
557K/s
separate loops (big N)
330/s
single loop (big N)
311/s
View exact numbers
Test name
Executions per second
✓
single loop (small N)
653,530 Ops/sec
separate loops (small N)
556,956 Ops/sec
separate loops (big N)
330 Ops/sec
single loop (big N)
311 Ops/sec
Script Preparation code:
const smallN = 2 ** 10 const bigN = 2 ** 20 const arr1 = [] const arr2 = [] for (let i = 0; i < bigN; ++i) { arr1.push(Math.random()) arr2.push(Math.random()) }
Tests:
single loop (big N)
for (let i = 0; i < bigN; ++i) { arr1[i] *= 2 arr2[i] *= 2 }
separate loops (big N)
for (let i = 0; i < bigN; ++i) arr1[i] *= 2 for (let i = 0; i < bigN; ++i) arr2[i] *= 2
single loop (small N)
for (let i = 0; i < smallN; ++i) { arr1[i] *= 2 arr2[i] *= 2 }
separate loops (small N)
for (let i = 0; i < smallN; ++i) arr1[i] *= 2 for (let i = 0; i < smallN; ++i) arr2[i] *= 2