-
-
Notifications
You must be signed in to change notification settings - Fork 35.5k
Expand file tree
/
Copy pathmetrics-observable.js
More file actions
38 lines (30 loc) · 854 Bytes
/
metrics-observable.js
File metadata and controls
38 lines (30 loc) · 854 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
'use strict';
const assert = require('assert');
const common = require('../common.js');
const { metrics } = require('perf_hooks');
const bench = common.createBenchmark(main, {
n: [1e5, 1e6],
observableCount: [1, 10, 100],
});
function main({ n, observableCount }) {
// Create observable metrics
const subscriptions = {};
let counter = 0;
for (let i = 0; i < observableCount; i++) {
const name = `bench.observable.${i}`;
metrics.create(name, {
unit: 'count',
observable: (m) => { m.record(counter++); },
});
subscriptions[name] = { aggregation: 'lastValue' };
}
const consumer = metrics.createConsumer(subscriptions);
bench.start();
for (let i = 0; i < n; i++) {
consumer.collect();
}
bench.end(n);
// Cleanup and avoid deadcode elimination
assert.ok(counter > 0);
consumer.close();
}