stats

package
v2.9.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 23, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package stats implements performant statistics implementations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Pool

type Pool struct {
	// contains filtered or unexported fields
}

Pool is a pool of samples.

func NewPool

func NewPool(percLimit int) *Pool

NewPool returns a pool.

func (*Pool) Get

func (p *Pool) Get() *Sample

Get returns a sample from the pool, creating one if necessary.

func (*Pool) Put

func (p *Pool) Put(s *Sample)

Put adds a sample to the pool.

type Sample

type Sample struct {
	// contains filtered or unexported fields
}

Sample calculates incremental statistics such as mean, variance, standard deviation and estimates percentiles.

The incremental stats are based on the algorithm described here: https://en.wikipedia.org/wiki/Algorithms_for_calculating_variance .

func NewSample

func NewSample(percLimit int) *Sample

NewSample returns a sample with the given percentile sample limit.

func (*Sample) Add

func (s *Sample) Add(v float64)

Add adds a sample value.

func (*Sample) Count

func (s *Sample) Count() int64

Count returns the number of values in the sample.

func (*Sample) Max

func (s *Sample) Max() float64

Max returns the max of the sample.

func (*Sample) Mean

func (s *Sample) Mean() float64

Mean returns the mean of the sample.

func (*Sample) Min

func (s *Sample) Min() float64

Min returns the min of the sample.

func (*Sample) Percentiles

func (s *Sample) Percentiles(ns []float64) []float64

Percentiles returns the estimated percentiles of the sample.

The returned slice is backed by internal storage and is only valid until the next call to Percentiles or Reset on this Sample.

func (*Sample) Reset

func (s *Sample) Reset()

Reset resets the sample.

func (*Sample) StdDev

func (s *Sample) StdDev() float64

StdDev returns the standard deviation of the sample.

func (*Sample) Sum

func (s *Sample) Sum() float64

Sum returns the sum of the sample.

func (*Sample) Variance

func (s *Sample) Variance() float64

Variance returns the variance of the sample.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL