HDR Histogram (Numpy-based)

0.3.3 · active · verified Thu Apr 16

hdrpy is a Python library that provides a NumPy-based implementation of High Dynamic Range (HDR) histograms. It was initially forked from HDRHistogram_py and replaced its C code dependency with NumPy. This library is designed for efficient recording and analyzing of sampled data value counts across a configurable integer range with specified value precision, making it particularly useful in latency and performance-sensitive applications.

Common errors

Warnings

Install

Imports

Quickstart

Initialize an HdrHistogram instance, record values, and retrieve various statistics like mean, standard deviation, and percentiles.

import random
from hdrpy import HdrHistogram

# Create a histogram that can track values from 1 to 3,600,000,000
# with 3 significant digits of precision (e.g., 1 microsecond to 1 hour)
histogram = HdrHistogram(1, 3600 * 1000 * 1000, 3)

# Record some simulated latency values (in microseconds)
for _ in range(100000):
    latency = random.randint(100, 5000000) # values between 0.1ms and 5s
    histogram.record_value(latency)

# Record a value with correction for coordinated omission (e.g., expected interval of 10ms)
histogram.record_corrected_value(random.randint(100, 5000000), 10000)

print(f"Total count: {histogram.get_total_count()}")
print(f"Mean: {histogram.get_mean()} µs")
print(f"Standard Deviation: {histogram.get_stddev()} µs")
print(f"99th Percentile: {histogram.get_value_at_percentile(99.0)} µs")
print(f"Max Value: {histogram.get_max_value()} µs")

view raw JSON →