rate

package
v1.13.1-rc2 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2023 License: BSD-3-Clause Imports: 2 Imported by: 2 modules, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Rate

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

func New

func New(windowsSize time.Duration) *Rate

New returns a new rate tracker with a defined window size that must be greater than one millisecond.

func (*Rate) Add

func (r *Rate) Add(count int)

add uses the current time and rounds it down to a window and increments the window's value.

func (*Rate) Rate

func (r *Rate) Rate() float64

rate uses the current window and previous windows' counter to compute a moving-window rate in seconds. the rate is computed by first calculating how far along the current time is in the current window as a ratio between 0 and 1.0. Then, the sum of currentWindowCount + (1 - ratio) * previousWindowCounter is returned as the interpolated counter between the two windows.

Jump to

Keyboard shortcuts

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