forked from HdrHistogram/hdrhistogram-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example_hdr_test.go
63 lines (55 loc) · 2.14 KB
/
example_hdr_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package hdrhistogram_test
import (
"fmt"
"github.com/filipecosta90/hdrhistogram"
)
// This latency Histogram could be used to track and analyze the counts of
// observed integer values between 0 us and 30000000 us ( 30 secs )
// while maintaining a value precision of 4 significant digits across that range,
// translating to a value resolution of :
// - 1 microsecond up to 10 milliseconds,
// - 100 microsecond (or better) from 10 milliseconds up to 10 seconds,
// - 300 microsecond (or better) from 10 seconds up to 30 seconds,
func ExampleNew() {
lH := hdrhistogram.New(1, 30000000, 4)
input := []int64{
459876, 669187, 711612, 816326, 931423, 1033197, 1131895, 2477317,
3964974, 12718782,
}
for _, sample := range input {
lH.RecordValue(sample)
}
fmt.Printf("Percentile 50: %d\n", lH.ValueAtQuantile(50.0))
// Output:
// Percentile 50: 931423
}
// This latency Histogram could be used to track and analyze the counts of
// observed integer values between 0 us and 30000000 us ( 30 secs )
// while maintaining a value precision of 3 significant digits across that range,
// translating to a value resolution of :
// - 1 microsecond up to 1 millisecond,
// - 1 millisecond (or better) up to one second,
// - 1 second (or better) up to it's maximum tracked value ( 30 seconds ).
func ExampleHistogram_RecordValue() {
lH := hdrhistogram.New(1, 30000000, 3)
input := []int64{
459876, 669187, 711612, 816326, 931423, 1033197, 1131895, 2477317,
3964974, 12718782,
}
for _, sample := range input {
lH.RecordValue(sample)
}
fmt.Println(lH.PercentilesPrint(1, 1.0))
// Output:
// Value Percentile TotalCount 1/(1-Percentile)
//
// 460031.000 0.000000 1 1.00
// 931839.000 0.500000 5 2.00
// 2478079.000 0.750000 8 4.00
// 3966975.000 0.875000 9 8.00
// 12722175.000 0.937500 10 16.00
// 12722175.000 1.000000 10 +Inf
// #[Mean = 2491481.600, StdDeviation = 3557920.109]
// #[Max = 12722175.000, Total count = 10]
// #[Buckets = 15, SubBuckets = 2048]
}