MessageChannels - Many Messages vs. Many Channels (v2)

Revision 2 of this benchmark created on


Setup

let chans = 100;
let msgs = 100 * chans;

let channels = Array(chans).fill().map(() => new MessageChannel());
let senders = channels.map(mc => mc.port1);
let responders = channels.map(mc => mc.port2);

// pre-create promises with external resolvers
let resolver = Array(msgs).fill();
let promises = Array(msgs).fill().map((_, i) => new Promise(r => resolver[i] = r));

// echo from other end
responders.forEach(p => p.onmessage = ({data}) => p.postMessage({ id: data.id }));
// register promise resolvers AoT
senders.forEach(p => p.onmessage = ({data}) => resolver[data.id]());

Test runner

Ready to run.

Testing in
TestOps/sec
All Messages in one Channel
for (let i = 0; i < msgs; i++) {
	senders[0].postMessage({ id: i });
};
console.log("done sending");
Promise.all(promises).then(() => deferred.resolve());
ready
Spread Messages over Channels
for (let i = 0; i < msgs; i++) {
	senders[i % chans].postMessage({ id: i });
};
console.log("done sending");
Promise.all(promises).then(() => deferred.resolve());
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.