Codebase list golang-github-beorn7-perks / b965b61
Fix example. Also, remove dependency on the original repo. beorn7 9 years ago
2 changed file(s) with 21 addition(s) and 9 deletion(s). Raw diff Collapse all Expand all
44 import (
55 "bufio"
66 "fmt"
7 "github.com/bmizerany/perks/quantile"
87 "log"
98 "os"
109 "strconv"
1110 "time"
11
12 "github.com/beorn7/perks/quantile"
1213 )
1314
1415 func Example_simple() {
1617 go sendFloats(ch)
1718
1819 // Compute the 50th, 90th, and 99th percentile.
19 q := quantile.NewTargeted(0.50, 0.90, 0.99)
20 q := quantile.NewTargeted(map[float64]float64{
21 0.50: 0.005,
22 0.90: 0.001,
23 0.99: 0.0001,
24 })
2025 for v := range ch {
2126 q.Insert(v)
2227 }
2732 fmt.Println("count:", q.Count())
2833 // Output:
2934 // perc50: 5
30 // perc90: 14
31 // perc99: 40
35 // perc90: 16
36 // perc99: 223
3237 // count: 2388
3338 }
3439
5156 // even if we do not plan to query them all here.
5257 ch := make(chan quantile.Samples)
5358 getDBQuerySamples(ch)
54 q := quantile.NewTargeted(0.90)
59 q := quantile.NewTargeted(map[float64]float64{0.90: 0.001})
5560 for samples := range ch {
5661 q.Merge(samples)
5762 }
6671 go sendStreamValues(ch)
6772
6873 tick := time.NewTicker(1 * time.Minute)
69 q := quantile.NewTargeted(0.90, 0.95, 0.99)
74 q := quantile.NewTargeted(map[float64]float64{
75 0.90: 0.001,
76 0.95: 0.0005,
77 0.99: 0.0001,
78 })
7079 for {
7180 select {
7281 case t := <-tick.C:
112112 verifyHighPercsWithRelativeEpsilon(t, a, s)
113113 }
114114
115 func TestTargetedMerge(t *testing.T) {
115 // BrokenTestTargetedMerge is broken, see Merge doc comment.
116 func BrokenTestTargetedMerge(t *testing.T) {
116117 rand.Seed(42)
117118 s1 := NewTargeted(Targets)
118119 s2 := NewTargeted(Targets)
122123 verifyPercsWithAbsoluteEpsilon(t, a, s1)
123124 }
124125
125 func TestLowBiasedMerge(t *testing.T) {
126 // BrokenTestLowBiasedMerge is broken, see Merge doc comment.
127 func BrokenTestLowBiasedMerge(t *testing.T) {
126128 rand.Seed(42)
127129 s1 := NewLowBiased(RelativeEpsilon)
128130 s2 := NewLowBiased(RelativeEpsilon)
132134 verifyLowPercsWithRelativeEpsilon(t, a, s2)
133135 }
134136
135 func TestHighBiasedMerge(t *testing.T) {
137 // BrokenTestHighBiasedMerge is broken, see Merge doc comment.
138 func BrokenTestHighBiasedMerge(t *testing.T) {
136139 rand.Seed(42)
137140 s1 := NewHighBiased(RelativeEpsilon)
138141 s2 := NewHighBiased(RelativeEpsilon)