-
-
Notifications
You must be signed in to change notification settings - Fork 35.5k
Expand file tree
/
Copy pathmetrics-aggregator-summary.js
More file actions
39 lines (31 loc) · 915 Bytes
/
metrics-aggregator-summary.js
File metadata and controls
39 lines (31 loc) · 915 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
39
'use strict';
const assert = require('assert');
const common = require('../common.js');
const { metrics } = require('perf_hooks');
const bench = common.createBenchmark(main, {
n: [1e6, 1e7],
quantileCount: [3, 5, 10],
});
function main({ n, quantileCount }) {
const metric = metrics.create('bench.aggregator.summary', { unit: 'ms' });
// Generate quantiles
const quantiles = [];
for (let i = 1; i <= quantileCount; i++) {
quantiles.push(i / (quantileCount + 1));
}
const consumer = metrics.createConsumer({
'bench.aggregator.summary': {
aggregation: 'summary',
quantiles,
},
});
bench.start();
for (let i = 0; i < n; i++) {
// Record values that simulate realistic latency distribution (min 1)
metric.record(Math.random() * 999 + 1);
}
bench.end(n);
// Cleanup and avoid deadcode elimination
assert.ok(consumer.collect());
consumer.close();
}