Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Multipromise resulter
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36
Browser:
Chrome 108
Operating system:
Windows
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
Function based
857.7 Ops/sec
Array based
844.3 Ops/sec
Script Preparation code:
function delay(ms, val = true) { let timeoutId; return new Promise(resolve => { timeoutId = setTimeout(() => resolve(val), ms); }); } function runTest(resultFunc) { const res = resultFunc(); for(let i=0; i<20; i++) { res.add(delay(i)); } return res.get(); }
Tests:
Function based
const createResultPromiseFunc = () => { let res = Promise.resolve(); return { get() { return res; }, add(nextPromise) { res = res.then(() => nextPromise); return this; } }; }; runTest(createResultPromiseFunc);
Array based
const createResultPromiseArray = () => { const res = []; return { get() { return Promise.all(res); }, add(nextPromise) { res.push(nextPromise); return this; } }; }; runTest(createResultPromiseArray);