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
Test name
Executions per second
slice
30059190.0 Ops/sec
for loop
13028219.0 Ops/sec
forEach
34328528.0 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); }; });