From 6c14731588d6921e2e14192b01545844fefba92b Mon Sep 17 00:00:00 2001 From: RafaelGSS Date: Tue, 3 Sep 2024 17:13:42 -0300 Subject: [PATCH 1/5] benchmark: enhance dc publish benchmark --- benchmark/diagnostics_channel/publish.js | 29 +++++++++++++++++++----- 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/benchmark/diagnostics_channel/publish.js b/benchmark/diagnostics_channel/publish.js index 3a30012ba692b8..f743161c7dee9d 100644 --- a/benchmark/diagnostics_channel/publish.js +++ b/benchmark/diagnostics_channel/publish.js @@ -1,27 +1,44 @@ 'use strict'; const common = require('../common.js'); -const dc = require('diagnostics_channel'); +const dc = require('node:diagnostics_channel'); const bench = common.createBenchmark(main, { n: [1e8], + checkSubscribers: [1, 0], + objSize: [10, 1e2, 1e3], subscribers: [0, 1, 10], }); function noop() {} -function main({ n, subscribers }) { +function createObj(size) { + return Array.from({ length: size }, (n) => ({ + foo: 'yarp', + nope: { + bar: '123', + a: [1, 2, 3], + baz: n, + c: {}, + b: [], + }, + })); +} + +function main({ n, subscribers, checkSubscribers, objSize }) { const channel = dc.channel('test'); for (let i = 0; i < subscribers; i++) { channel.subscribe(noop); } - const data = { - foo: 'bar', - }; + const data = createObj(objSize); bench.start(); for (let i = 0; i < n; i++) { - if (channel.hasSubscribers) { + if (checkSubscribers) { + if(channel.hasSubscribers) { + channel.publish(data); + } + } else { channel.publish(data); } } From 13eff4acfb501cca9425515eff6ea6d64511c73a Mon Sep 17 00:00:00 2001 From: RafaelGSS Date: Tue, 3 Sep 2024 17:19:33 -0300 Subject: [PATCH 2/5] fixup! benchmark: enhance dc publish benchmark --- benchmark/diagnostics_channel/publish.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/benchmark/diagnostics_channel/publish.js b/benchmark/diagnostics_channel/publish.js index f743161c7dee9d..cf897403ed2b1d 100644 --- a/benchmark/diagnostics_channel/publish.js +++ b/benchmark/diagnostics_channel/publish.js @@ -35,7 +35,7 @@ function main({ n, subscribers, checkSubscribers, objSize }) { bench.start(); for (let i = 0; i < n; i++) { if (checkSubscribers) { - if(channel.hasSubscribers) { + if (channel.hasSubscribers) { channel.publish(data); } } else { From 33ca0dc635aea94061d427772de8437a436778c9 Mon Sep 17 00:00:00 2001 From: Rafael Gonzaga Date: Tue, 3 Sep 2024 19:51:36 -0300 Subject: [PATCH 3/5] Update benchmark/diagnostics_channel/publish.js Co-authored-by: Almeida --- benchmark/diagnostics_channel/publish.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/benchmark/diagnostics_channel/publish.js b/benchmark/diagnostics_channel/publish.js index cf897403ed2b1d..66a091cd08474e 100644 --- a/benchmark/diagnostics_channel/publish.js +++ b/benchmark/diagnostics_channel/publish.js @@ -34,11 +34,7 @@ function main({ n, subscribers, checkSubscribers, objSize }) { bench.start(); for (let i = 0; i < n; i++) { - if (checkSubscribers) { - if (channel.hasSubscribers) { - channel.publish(data); - } - } else { + if (!checkSubscribers || channel.hasSubscribers) { channel.publish(data); } } From 61a1e7b76adfc84368c31f8f5a3db2f411960cf0 Mon Sep 17 00:00:00 2001 From: RafaelGSS Date: Tue, 3 Sep 2024 23:18:00 -0300 Subject: [PATCH 4/5] fixup! Update benchmark/diagnostics_channel/publish.js --- benchmark/diagnostics_channel/publish.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/benchmark/diagnostics_channel/publish.js b/benchmark/diagnostics_channel/publish.js index 66a091cd08474e..ba40054ce4146c 100644 --- a/benchmark/diagnostics_channel/publish.js +++ b/benchmark/diagnostics_channel/publish.js @@ -32,11 +32,19 @@ function main({ n, subscribers, checkSubscribers, objSize }) { const data = createObj(objSize); - bench.start(); - for (let i = 0; i < n; i++) { - if (!checkSubscribers || channel.hasSubscribers) { + const publishWithCheck = (data) => { + if (channel.hasSubscribers) { channel.publish(data); } + }; + const publishWithoutCheck = (data) => { + channel.publish(data); + }; + + const fn = checkSubscribers ? publishWithCheck : publishWithoutCheck; + bench.start(); + for (let i = 0; i < n; i++) { + fn(data); } bench.end(n); } From 834c60247af8ab5af816deacc2da5a84d5def506 Mon Sep 17 00:00:00 2001 From: RafaelGSS Date: Tue, 3 Sep 2024 23:28:49 -0300 Subject: [PATCH 5/5] fixup! fixup! Update benchmark/diagnostics_channel/publish.js --- benchmark/diagnostics_channel/publish.js | 30 +++++++++++++++--------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/benchmark/diagnostics_channel/publish.js b/benchmark/diagnostics_channel/publish.js index ba40054ce4146c..6d8e40a6b733f6 100644 --- a/benchmark/diagnostics_channel/publish.js +++ b/benchmark/diagnostics_channel/publish.js @@ -30,21 +30,29 @@ function main({ n, subscribers, checkSubscribers, objSize }) { channel.subscribe(noop); } - const data = createObj(objSize); + const publishWithCheck = () => { + const data = createObj(objSize); + bench.start(); + for (let i = 0; i < n; i++) { + if (channel.hasSubscribers) { + channel.publish(data); + } + } + bench.end(n); + }; - const publishWithCheck = (data) => { - if (channel.hasSubscribers) { + const publishWithoutCheck = () => { + const data = createObj(objSize); + bench.start(); + for (let i = 0; i < n; i++) { channel.publish(data); } - }; - const publishWithoutCheck = (data) => { - channel.publish(data); + bench.end(n); }; - const fn = checkSubscribers ? publishWithCheck : publishWithoutCheck; - bench.start(); - for (let i = 0; i < n; i++) { - fn(data); + if (checkSubscribers) { + publishWithCheck(); + } else { + publishWithoutCheck(); } - bench.end(n); }