项目作者: flyingmutant

项目描述 :
B-digest is a Go library for fast and memory-efficient estimation of quantiles with guaranteed relative error and full mergeability
高级语言: Go
项目地址: git://github.com/flyingmutant/bdigest.git
创建时间: 2020-05-01T09:20:14Z
项目社区:https://github.com/flyingmutant/bdigest

开源协议:Apache License 2.0

下载


b-digest PkgGoDev CI

B-digest is a Go library for fast and memory-efficient estimation
of quantiles with guaranteed relative error and full mergeability.

  1. package bdigest_test
  2. import (
  3. "fmt"
  4. "math"
  5. "math/rand"
  6. "pgregory.net/bdigest"
  7. )
  8. func ExampleNewDigest() {
  9. r := rand.New(rand.NewSource(0))
  10. d := bdigest.NewDigest(0.05)
  11. for i := 0; i < 100000; i++ {
  12. v := math.Exp(r.NormFloat64())
  13. d.Add(v)
  14. }
  15. fmt.Printf("%v buckets\n", d.Size())
  16. for _, q := range []float64{0, 0.1, 0.25, 0.5, 0.75, 0.9, 0.95, 0.99, 0.999, 0.9999, 1} {
  17. fmt.Printf("%v\tq%v\n", d.Quantile(q), q)
  18. }
  19. // Output:
  20. // 98 buckets
  21. // 0.015690260723105844 q0
  22. // 0.2858480802952493 q0.1
  23. // 0.5211100423907477 q0.25
  24. // 1.05 q0.5
  25. // 1.9141830301785612 q0.75
  26. // 3.489615879070075 q0.9
  27. // 5.2076333497857386 q0.95
  28. // 10.493014090054524 q0.99
  29. // 21.142683691165157 q0.999
  30. // 42.601017193748824 q0.9999
  31. // 258.10858921508054 q1
  32. }

License

B-digest is licensed under the Apache License Version 2.0.