-
-
Notifications
You must be signed in to change notification settings - Fork 35.5k
Expand file tree
/
Copy pathmetrics-aggregator-histogram.js
More file actions
43 lines (34 loc) · 1.03 KB
/
metrics-aggregator-histogram.js
File metadata and controls
43 lines (34 loc) · 1.03 KB
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
39
40
41
42
43
'use strict';
const assert = require('assert');
const common = require('../common.js');
const { metrics } = require('perf_hooks');
const bench = common.createBenchmark(main, {
n: [1e7, 1e8],
boundaryCount: [5, 10, 20, 50],
});
function main({ n, boundaryCount }) {
const metric = metrics.create('bench.aggregator.histogram', { unit: 'ms' });
// Generate exponential boundaries like OTel defaults
const boundaries = [];
for (let i = 0; i < boundaryCount; i++) {
boundaries.push(Math.pow(2, i));
}
const consumer = metrics.createConsumer({
'bench.aggregator.histogram': {
aggregation: 'histogram',
boundaries,
},
});
// Generate values that spread across buckets
const maxBoundary = boundaries[boundaries.length - 1];
bench.start();
for (let i = 0; i < n; i++) {
// Distribute values across the range
const value = (i % (maxBoundary + 1));
metric.record(value);
}
bench.end(n);
// Cleanup and avoid deadcode elimination
assert.ok(consumer.collect());
consumer.close();
}