Manuscript Documentation
v2026.12.0

@std/data/histogram.ms#

Import each required symbol with import Name from "@std/data/histogram.ms".

Histogram Type#

A latency histogram. It records non-negative Int values, usually nanoseconds, in fixed memory and answers count, extremes, mean and percentiles.

Values below 64 are exact. Larger values fall in buckets about 3% wide, so a percentile is an upper bound within that error. A histogram has one owner; other promises send their observations to that owner over a pipe.

Example: latency.time(() => handle(request)) records one span, and latency.percentile(99.0) returns the value that 99% of observations do not exceed.

Manuscript
opaque type Histogram {
}

Histogram.count#

Observations recorded so far.

Manuscript
fn count() Int

Histogram.max#

Largest observation, or null when empty.

Manuscript
fn max() Int?

Histogram.mean#

Mean of the observations, or 0.0 when empty. It is exact, not bucketed.

Manuscript
fn mean() Float

Histogram.min#

Smallest observation, or null when empty.

Manuscript
fn min() Int?

Histogram.percentile#

Value at or below which p percent of observations fall, for p in 0.0 through 100.0; null when empty. The answer is the top of the matching bucket, never above the largest observation. A p outside the range gives null.

Manuscript
fn percentile(p Float) Int?

Histogram.record#

Adds one observation. A negative value is recorded as 0, so a clock that steps back counts as an instant measurement.

Manuscript
var fn record(value Int) Void

Histogram.record_duration#

Adds one duration as nanoseconds. A negative duration is recorded as 0, like record.

Manuscript
var fn record_duration(elapsed Duration) Void

Histogram.reset#

Discards every observation and returns the histogram to its empty state.

Manuscript
var fn reset() Void

Histogram.time#

Runs work, records how long it took in nanoseconds on the monotonic clock, and returns its result. A normal return, including an error Result, is recorded; a fault or cancellation that prevents returning is not.

Manuscript
var fn time[T](work fn() T) T

histogram Function#

Creates an empty histogram.

Manuscript
fn histogram() Histogram { ... }