Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Batching
Batching strategy with yield benchmark
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/125.0.0.0 Safari/537.36
Browser:
Chrome 125
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
For loop
1.5 Ops/sec
Yield
2.2 Ops/sec
Script Preparation code:
function chunkArray(arr, chunkSize) { const result = []; for (let i = 0; i < arr.length; i += chunkSize) { const chunk = arr.slice(i, i + chunkSize); result.push(chunk); } return result; }
Tests:
For loop
function task(data) { return new Promise((resolve, reject) => { const results = data.reduce((acc, curr) => acc + curr, 0) resolve(results) }) } const datasets = [...Array(5_000_000).keys()] for (chunk of chunkArray(datasets, 10000)) { task(chunk).then( (res) => { // } ) }
Yield
function* task(data) { return new Promise((resolve, reject) => { const results = data.reduce((acc, curr) => acc + curr, 0) resolve(results) }) } function* process(data) { for (chunk of chunkArray(data, 10000)) { yield task(chunk) } } const datasets = [...Array(5_000_000).keys()] for (data of process(datasets)) { const resp = data.next().value resp.then((res) => { // }) }