Skip to content

prep/average

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

average TravisCI Go Report Card GoDoc

This stupidly named Go package contains a single struct that is used to implement counters on a sliding time window.

Usage

import (
    "fmt"

    "github.com/prep/average"
)

func main() {
    // Create a SlidingWindow that has a window of 15 minutes, with a
    // granulity of 1 minute.
    sw := average.MustNew(15 * time.Minute, time.Minute)
    defer sw.Stop()

    // Do some work.
    sw.Add(15)
    // Do some more work.
    sw.Add(22)
    // Do even more work.
    sw.Add(22)

    fmt.Printf("Average of last  1m: %f\n", sw.Average(time.Minute)
    fmt.Printf("Average of last  5m: %f\n", sw.Average(5 * time.Minute)
    fmt.Printf("Average of last 15m: %f\n\n", sw.Average(15 * time.Minute)

    total, numSamples := sw.Total(15 * time.Minute)
    fmt.Printf("Counter has a total of %d over %d samples", total, numSamples)
}

License

This software is created for MessageBird B.V. and distributed under the BSD-style license found in the LICENSE file.

About

A sliding time window for Go

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy