GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — benchmark: enhance dc publish benchmark · nodejs/node@ebe91db

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • benchmark/diagnostics_channel
    • publish.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎benchmark/diagnostics_channel/publish.js‎

Copy file name to clipboard
+37-8Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,58 @@
11
'use strict';
22
const common = require('../common.js');
3-
const dc = require('diagnostics_channel');
3+
const dc = require('node:diagnostics_channel');
44

55
const bench = common.createBenchmark(main, {
66
n: [1e8],
7+
checkSubscribers: [1, 0],
8+
objSize: [10, 1e2, 1e3],
79
subscribers: [0, 1, 10],
810
});
911

1012
function noop() {}
1113

12-
function main({ n, subscribers }) {
14+
function createObj(size) {
15+
return Array.from({ length: size }, (n) => ({
16+
foo: 'yarp',
17+
nope: {
18+
bar: '123',
19+
a: [1, 2, 3],
20+
baz: n,
21+
c: {},
22+
b: [],
23+
},
24+
}));
25+
}
26+
27+
function main({ n, subscribers, checkSubscribers, objSize }) {
1328
const channel = dc.channel('test');
1429
for (let i = 0; i < subscribers; i++) {
1530
channel.subscribe(noop);
1631
}
1732

18-
const data = {
19-
foo: 'bar',
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);
2042
};
2143

22-
bench.start();
23-
for (let i = 0; i < n; i++) {
24-
if (channel.hasSubscribers) {
44+
const publishWithoutCheck = () => {
45+
const data = createObj(objSize);
46+
bench.start();
47+
for (let i = 0; i < n; i++) {
2548
channel.publish(data);
2649
}
50+
bench.end(n);
51+
};
52+
53+
if (checkSubscribers) {
54+
publishWithCheck();
55+
} else {
56+
publishWithoutCheck();
2757
}
28-
bench.end(n);
2958
}

0 commit comments

Comments
0 (0)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.