ComputeStats computes basic statistics about r.
()
| 53 | |
| 54 | // ComputeStats computes basic statistics about r. |
| 55 | func (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. |
| 84 | func DisableColor() { |
no outgoing calls