On this page

C

Histogram

History
M

histogram.burnRate

History
histogram.burnRate(sloTarget): number
Attributes
sloTarget:number
The SLO target as a fraction between 0 and 1 (exclusive). For example, 0.999 for a 99.9% SLO.
Returns:number

Returns the SLO burn rate: ewmaErrorRate / (1 - sloTarget). A burn rate of 1 means the error budget will be exactly exhausted over the SLO window. A burn rate greater than 1 means it is being consumed faster than allowed. Requires the histogram to have been created with both halfLife and threshold options.

const { createHistogram } = require('node:perf_hooks');

// Track latency with a 200ms SLO threshold, half-life of 100 samples
const h = createHistogram({ halfLife: 100, threshold: 200_000_000 });

// ... record latency values ...

// Check burn rate against a 99.9% SLO
const rate = h.burnRate(0.999);
if (rate > 1) {
  console.log(`SLO burn rate: ${rate.toFixed(2)}x — error budget depleting`);
}
P

histogram.count

History
Type:number

The number of samples recorded by the histogram.

P

histogram.countBigInt

History
Type:bigint

The number of samples recorded by the histogram.

M

histogram.ccdf

History
histogram.ccdf(value): number
Attributes
value:number
The value to query.
Returns:number
A probability between 0.0 and 1.0.

Returns the complementary cumulative distribution function (CCDF) value for the given value, representing the probability that a recorded value will exceed value. Equivalent to 1 - histogram.cdf(value).

M

histogram.cdf

History
histogram.cdf(value): number
Attributes
value:number
The value to query.
Returns:number
A probability between 0.0 and 1.0.

Returns the cumulative distribution function (CDF) value for the given value, representing the probability that a recorded value will be less than or equal to value. This is the inverse operation of histogram.percentile().

M

histogram.cliffsD

History
histogram.cliffsD(other): number
Attributes
other:Histogram
The histogram to compare against.
Returns:number
A value between -1.0 and 1.0.

Computes Cliff's delta, a non-parametric effect size measure. Returns the probability that a random value from this histogram exceeds a random value from other, minus the reverse probability. A value of 1 means every value in this histogram exceeds every value in other; -1 means the opposite; 0 means no tendency in either direction.

M

histogram.cohensD

History
histogram.cohensD(other): number
Attributes
other:Histogram
The histogram to compare against.
Returns:number
The effect size.

Computes Cohen's d effect size, the standardized difference between the means of this histogram and other, using the pooled standard deviation. Positive values indicate this histogram has a higher mean. By convention, |d| < 0.2 is a small effect, 0.5 is medium, and 0.8 or greater is large. Both histograms must have at least 2 recorded values; otherwise returns 0.

M

histogram.countAt

History
histogram.countAt(value): number
Attributes
value:number
The value to query.
Returns:number

Returns the number of recorded values that fall within the equivalent value range of the given value.

P

histogram.exceeds

History
Type:number

The number of times the event loop delay exceeded the maximum 1 hour event loop delay threshold.

P

histogram.exceedsBigInt

History
Type:bigint

The number of times the event loop delay exceeded the maximum 1 hour event loop delay threshold.

M

histogram.export

History
histogram.export(): Uint8Array
Returns:Uint8Array

Serializes the histogram to a CBOR-encoded (RFC 8949) Uint8Array suitable for transmission or persistent storage. The encoding uses a delta-encoded sparse representation of the bucket counts, so the output size scales with the number of distinct recorded values rather than the total bucket count.

The output includes all histogram configuration, bucket data, and EWMA state (when enabled). It can be reconstructed into a new histogram using perf_hooks.importHistogram().

The CBOR payload is a map with integer keys:

KeyTypeField
0uintFormat version (currently 1)
1uintLowest discernible value
2uintHighest trackable value
3uintSignificant figures
4uintTotal count
5uintMin value
6uintMax value
7uintNormalizing index offset
8float64Conversion ratio
9uintCounts array length
10arrayDelta-encoded sparse counts [delta, c, ...]
11mapEWMA state (omitted when disabled)

Any standard CBOR decoder can parse the output.

P

histogram.ewmaMean

History
Type:number

The exponentially weighted moving average of recorded values. Only active when the histogram was created with a halfLife option greater than 0. Returns 0 when EWMA is disabled or no values have been recorded.

P

histogram.ewmaStddev

History
Type:number

The exponentially weighted moving standard deviation. Only active when the histogram was created with a halfLife option greater than 0. Returns 0 when EWMA is disabled or no values have been recorded.

P

histogram.ewmaErrorRate

History
Type:number

The EWMA-smoothed probability of a recorded value exceeding the configured threshold. Only active when the histogram was created with both halfLife and threshold options. Returns 0 when not enabled or no values have been recorded.

M

histogram.ksTest

History
histogram.ksTest(other): number
Attributes
other:Histogram
The histogram to compare against.
Returns:number
The KS D-statistic, between 0.0 and 1.0.

Computes the Kolmogorov-Smirnov test statistic comparing this histogram's distribution to other. A value of 0 indicates identical distributions; values close to 1 indicate completely disjoint distributions. Useful for detecting performance regressions by comparing before/after histograms.

P

histogram.kurtosis

History
Type:number

The excess kurtosis of the recorded values. Measures the heaviness of the distribution's tails relative to a normal distribution. Positive values indicate heavier tails (more extreme outliers); negative values indicate lighter tails.

M

histogram.linearBuckets

History
histogram.linearBuckets(stepSize): Map
Attributes
stepSize:number
The width of each linear bucket.
Returns:Map
A map of bucket boundary values to counts.

Returns the histogram data rebucketed into linearly-spaced intervals of stepSize. Useful for visualization and export.

M

histogram.logBuckets

History
histogram.logBuckets(firstBucket, base): Map
Attributes
firstBucket:number
The value of the first bucket boundary.
base:number
The logarithmic base for bucket width growth. Must be > 1.
Returns:Map
A map of bucket boundary values to counts.

Returns the histogram data rebucketed into logarithmically-spaced intervals, where each bucket's width is multiplied by base. Useful for visualization and export.

M

histogram.mannWhitneyTest

History
histogram.mannWhitneyTest(other): Object
Attributes
other:Histogram
The histogram to compare against.
Returns:Object
uStatistic:number
The Mann-Whitney U statistic.
zScore:number
The z-score (normal approximation).
pValue:number
Two-tailed p-value.

Performs a Mann-Whitney U test comparing whether this histogram tends to produce larger or smaller values than other. Unlike welchTest(), this is a non-parametric test that makes no assumptions about the shape of the distributions. Uses the normal approximation with tie correction for the p-value.

P

histogram.max

History
Type:number

The maximum recorded event loop delay.

P

histogram.maxBigInt

History
Type:bigint

The maximum recorded event loop delay.

P

histogram.mean

History
Type:number

The mean of the recorded event loop delays.

M

histogram.meanCI

History
histogram.meanCI(options?): Object
Attributes
options:Object
confidence?:number
The confidence level for the interval, between 0 and 1 (exclusive). Default: 0.95.
Returns:Object
mean:number
The mean estimate, equivalent to histogram.mean.
lower:number
The lower bound of the confidence interval.
upper:number
The upper bound of the confidence interval.

Returns a two-sided confidence interval for the mean using Student's t-distribution and the sample standard error. A higher confidence level produces a wider interval. This interval assumes that samples are independent and approximately normally distributed, although the approximation is robust for sufficiently large samples.

The result reflects the histogram's configured precision and is calculated from the values represented by its buckets. With fewer than two recorded values, lower and upper are NaN. When all recorded values are equal, lower and upper equal mean.

const { createHistogram } = require('node:perf_hooks');

const h = createHistogram();
for (let i = 1; i <= 100; i++) h.record(i);

const { mean, lower, upper } = h.meanCI();
console.log(`mean=${mean}, 95% CI=[${lower}, ${upper}]`);
P

histogram.min

History
Type:number

The minimum recorded event loop delay.

P

histogram.minBigInt

History
Type:bigint

The minimum recorded event loop delay.

M

histogram.percentile

History
histogram.percentile(percentile): number
Attributes
percentile:number
A percentile value in the range (0, 100].
Returns:number

Returns the value at the given percentile.

M

histogram.percentileBigInt

History
histogram.percentileBigInt(percentile): bigint
Attributes
percentile:number
A percentile value in the range (0, 100].
Returns:bigint

Returns the value at the given percentile.

M

histogram.percentileCI

History
histogram.percentileCI(percentile, options?): Object
Attributes
percentile:number
A percentile value in the range (0, 100].
options:Object
confidence?:number
The confidence level for the interval, between 0 and 1 (exclusive). Default: 0.95.
Returns:Object
value:number
The point estimate (same as histogram.percentile()).
lower:number
The lower bound of the confidence interval.
upper:number
The upper bound of the confidence interval.

Returns a confidence interval for the given percentile using the exact binomial method. With fewer samples, the interval will be wider, reflecting the greater uncertainty in the percentile estimate. Requires at least 2 recorded values; with fewer than 2, lower and upper will equal value.

const { createHistogram } = require('node:perf_hooks');

const h = createHistogram();
for (let i = 0; i < 1000; i++) {
  h.record(Math.floor(Math.random() * 100));
}

const ci = h.percentileCI(99);
console.log(ci.value);  // The p99 point estimate
console.log(ci.lower);  // The lower bound (95% confidence)
console.log(ci.upper);  // The upper bound (95% confidence)
P

histogram.percentiles

History
Type:Map

Returns a Map object detailing the accumulated percentile distribution.

P

histogram.percentilesBigInt

History
Type:Map

Returns a Map object detailing the accumulated percentile distribution.

M

histogram.percentilesAt

History
histogram.percentilesAt(percentiles): Map
Attributes
percentiles:number[]
An array of percentile values in the range (0, 100].
Returns:Map
A map of percentile values to their corresponding histogram values.

Returns the values at the specified percentiles, computed in a single efficient pass over the histogram data. More efficient than calling histogram.percentile() multiple times.

M

histogram.reset

History
histogram.reset(): void

Resets the collected histogram data.

P

histogram.skewness

History
Type:number

The skewness of the recorded values. Measures the asymmetry of the distribution. A positive value indicates a right-skewed distribution (longer right tail, common for latency data); a negative value indicates a left-skewed distribution.

P

histogram.stddev

History
Type:number

The standard deviation of the recorded event loop delays.

M

histogram.welchTest

History
histogram.welchTest(other, options?): Object
Attributes
other:Histogram
The histogram to compare against.
options:Object
confidence?:number
Confidence level for the interval, between 0 and 1. Default: 0.95.
Returns:Object
tStatistic:number
The Welch t-statistic.
degreesOfFreedom:number
Welch-Satterthwaite degrees of freedom.
pValue:number
Two-tailed p-value.
confidenceInterval:Object
lower:number
Lower bound of the confidence interval on the difference of means.
upper:number
Upper bound.

Performs Welch's t-test comparing the means of this histogram and other. The p-value indicates the probability of observing a difference at least this extreme under the null hypothesis that the two distributions have the same mean. Both histograms must have at least 2 recorded values; otherwise the result has pValue 1 and tStatistic 0.