• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2const common = require('../common.js');
3const dc = require('diagnostics_channel');
4
5const bench = common.createBenchmark(main, {
6  n: [1e8],
7  subscribers: [0, 1, 10],
8});
9
10function noop() {}
11
12function main({ n, subscribers }) {
13  const channel = dc.channel('test');
14  for (let i = 0; i < subscribers; i++) {
15    channel.subscribe(noop);
16  }
17
18  const data = {
19    foo: 'bar'
20  };
21
22  bench.start();
23  for (let i = 0; i < n; i++) {
24    if (channel.hasSubscribers) {
25      channel.publish(data);
26    }
27  }
28  bench.end(n);
29}
30