MCPcopy Index your code
hub / github.com/sourcegraph/checkup / ComputeStats

Method ComputeStats

types/result.go:55–81  ·  view source on GitHub ↗

ComputeStats computes basic statistics about r.

()

Source from the content-addressed store, hash-verified

53
54// ComputeStats computes basic statistics about r.
55func (r Result) ComputeStats() Stats {
56 var s Stats
57
58 for _, a := range r.Times {
59 s.Total += a.RTT
60 if a.RTT < s.Min || s.Min == 0 {
61 s.Min = a.RTT
62 }
63 if a.RTT > s.Max || s.Max == 0 {
64 s.Max = a.RTT
65 }
66 }
67 sorted := make(Attempts, len(r.Times))
68 copy(sorted, r.Times)
69 sort.Sort(sorted)
70
71 half := len(sorted) / 2
72 if len(sorted)%2 == 0 {
73 s.Median = (sorted[half-1].RTT + sorted[half].RTT) / 2
74 } else {
75 s.Median = sorted[half].RTT
76 }
77
78 s.Mean = time.Duration(int64(s.Total) / int64(len(r.Times)))
79
80 return s
81}
82
83// DisableColor disables ANSI colors in the Result default string.
84func DisableColor() {

Callers 7

StringMethod · 0.95
TestComputeStatsFunction · 0.80
concludeMethod · 0.80
concludeMethod · 0.80
concludeMethod · 0.80
concludeMethod · 0.80
concludeMethod · 0.80

Calls

no outgoing calls

Tested by 1

TestComputeStatsFunction · 0.64