diff options
author | Stephen Belanger <admin@stephenbelanger.com> | 2020-08-22 02:25:39 +0300 |
---|---|---|
committer | Node.js GitHub Bot <github-bot@iojs.org> | 2020-11-01 00:24:11 +0300 |
commit | c6c36c3da7187fca3a0f3f8348e764cba6d23099 (patch) | |
tree | 258662c208fb9c0f2f2c84bc3ed412ad1ce275bb /benchmark | |
parent | 5dd344a2a8a70d8c3b6e570c00b72f03d2801a84 (diff) |
lib: create diagnostics_channel module
PR-URL: https://github.com/nodejs/node/pull/34895
Reviewed-By: Bryan English <bryan@bryanenglish.com>
Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de>
Reviewed-By: Vladimir de Turckheim <vlad2t@hotmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Gabriel Schulhof <gabriel.schulhof@intel.com>
Reviewed-By: Michael Dawson <midawson@redhat.com>
Diffstat (limited to 'benchmark')
-rw-r--r-- | benchmark/diagnostics_channel/publish.js | 29 | ||||
-rw-r--r-- | benchmark/diagnostics_channel/subscribe.js | 19 |
2 files changed, 48 insertions, 0 deletions
diff --git a/benchmark/diagnostics_channel/publish.js b/benchmark/diagnostics_channel/publish.js new file mode 100644 index 00000000000..31a770c8627 --- /dev/null +++ b/benchmark/diagnostics_channel/publish.js @@ -0,0 +1,29 @@ +'use strict'; +const common = require('../common.js'); +const dc = require('diagnostics_channel'); + +const bench = common.createBenchmark(main, { + n: [1e8], + subscribers: [0, 1, 10], +}); + +function noop() {} + +function main({ n, subscribers }) { + const channel = dc.channel('test'); + for (let i = 0; i < subscribers; i++) { + channel.subscribe(noop); + } + + const data = { + foo: 'bar' + }; + + bench.start(); + for (let i = 0; i < n; i++) { + if (channel.hasSubscribers) { + channel.publish(data); + } + } + bench.end(n); +} diff --git a/benchmark/diagnostics_channel/subscribe.js b/benchmark/diagnostics_channel/subscribe.js new file mode 100644 index 00000000000..1415054588c --- /dev/null +++ b/benchmark/diagnostics_channel/subscribe.js @@ -0,0 +1,19 @@ +'use strict'; +const common = require('../common.js'); +const dc = require('diagnostics_channel'); + +const bench = common.createBenchmark(main, { + n: [1e8], +}); + +function noop() {} + +function main({ n }) { + const channel = dc.channel('channel.0'); + + bench.start(); + for (let i = 0; i < n; i++) { + channel.subscribe(noop); + } + bench.end(n); +} |