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 (iPhone; CPU iPhone OS 17_4_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.4.1 Mobile/15E148 Safari/604.1
Browser:
Mobile Safari 17
Operating system:
iOS 17.4.1
Device Platform:
Mobile
Date tested:
one year ago
Test name
Executions per second
For loop
9.5 Ops/sec
Yield
9.3 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) => { // }) }