Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Array slice vs for loop (2)
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/134.0.0.0 Safari/537.36
Browser:
Chrome 134
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
one year ago
forEach
34.4M/s
slice
30.6M/s
for loop
13.0M/s
View exact numbers
Test name
Executions per second
✓
forEach
34,423,564 Ops/sec
slice
30,589,032 Ops/sec
for loop
13,035,317 Ops/sec
Script Preparation code:
const data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0];
Tests:
slice
const copy = data.slice(3, 8) const copy2 = data.slice(0, 3)
for loop
const copy = []; const copy2 = []; for(let i = 0; i < data.length; i++) { if (i >=3 ) { copy.push(data[i]); } else { copy2.push(data[i]); }; };
forEach
const copy = []; const copy2 = []; data.forEach((el, i) => { if (i >=3 ) { copy.push(el); } else { copy2.push(el); }; });