Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Chunk array generator(slice) vs slice vs for loop
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:146.0) Gecko/20100101 Firefox/146.0
Browser:
Firefox 146
Operating system:
Windows
Device Platform:
Desktop
Date tested:
6 months ago
Test name
Executions per second
slice
22658.2 Ops/sec
push
22290.8 Ops/sec
generator (slice)
757923264.0 Ops/sec
Script Preparation code:
var data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0];
Tests:
slice
let chunksize = 10; let pos = 0; let chunk = []; while (pos <= data.length) { chunk = data.slice(pos, pos + chunksize); console.log(chunk); pos = pos + chunksize; }
push
let chunksize = 10; let pos = 0; let chunk = []; for (let pos = 0; pos <= data.length; pos++) { chunk.push(data[pos]); if (pos % chunksize === 0 || pos === data.length) { console.log(chunk); chunk = []; } }
generator (slice)
function* getBatch(records, currentPos = 0, chunksize = 10) { let pos = 0; while (pos <= records.length) { yield records.slice(pos, pos + chunksize); pos = pos + chunksize; } }