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 (X11; Linux x86_64; rv:147.0) Gecko/20100101 Firefox/147.0
Browser:
Firefox 147
Operating system:
Linux
Device Platform:
Desktop
Date tested:
3 months ago
Test name
Executions per second
single loop (big N)
724.8 Ops/sec
separate loops (big N)
643.2 Ops/sec
single loop (small N)
876063.8 Ops/sec
separate loops (small N)
815691.1 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