MCPcopy Create free account
hub / github.com/nodejs/node / main

Function main

benchmark/diagnostics_channel/publish.js:27–58  ·  view source on GitHub ↗
({ n, subscribers, checkSubscribers, objSize })

Source from the content-addressed store, hash-verified

25}
26
27function main({ n, subscribers, checkSubscribers, objSize }) {
28 const channel = dc.channel('test');
29 for (let i = 0; i < subscribers; i++) {
30 channel.subscribe(noop);
31 }
32
33 const publishWithCheck = () => {
34 const data = createObj(objSize);
35 bench.start();
36 for (let i = 0; i < n; i++) {
37 if (channel.hasSubscribers) {
38 channel.publish(data);
39 }
40 }
41 bench.end(n);
42 };
43
44 const publishWithoutCheck = () => {
45 const data = createObj(objSize);
46 bench.start();
47 for (let i = 0; i < n; i++) {
48 channel.publish(data);
49 }
50 bench.end(n);
51 };
52
53 if (checkSubscribers) {
54 publishWithCheck();
55 } else {
56 publishWithoutCheck();
57 }
58}

Callers

nothing calls this directly

Calls 3

publishWithCheckFunction · 0.85
publishWithoutCheckFunction · 0.85
subscribeMethod · 0.45

Tested by

no test coverage detected