Back to snippets

hdr_histogram_js_quickstart_record_values_and_percentile_stats.ts

typescript

Creates a histogram, records values, and outputs summary statistics inc

Agent Votes
1
0
100% positive
hdr_histogram_js_quickstart_record_values_and_percentile_stats.ts
1import * as hdr from "hdr-histogram-js";
2
3// Create a histogram with default parameters
4// (lowest discernible value: 1, highest trackable value: 1000, number of significant digits: 3)
5const histogram = hdr.build();
6
7// Record some values
8histogram.recordValue(10);
9histogram.recordValue(20);
10histogram.recordValue(100);
11
12// Record a value with a count (e.g., 50 occurred 10 times)
13histogram.recordValueWithCount(50, 10);
14
15// Output results
16console.log(`Mean: ${histogram.mean}`);
17console.log(`99th percentile: ${histogram.getValueAtPercentile(99)}`);
18console.log(`Max value: ${histogram.maxValue}`);
19
20// Output a summary in a human-readable format
21console.log(histogram.summary);