-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstats.go
More file actions
38 lines (31 loc) · 825 Bytes
/
stats.go
File metadata and controls
38 lines (31 loc) · 825 Bytes
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
package main
import (
"fmt"
"math"
"github.com/aclements/go-moremath/stats"
)
type StatCounter struct {
stats.Sample
}
func (sc *StatCounter) Add(s float64) {
sc.Sample.Xs = append(sc.Sample.Xs, s)
}
func (sc *StatCounter) PrintStats(msg string) {
if len(sc.Xs) == 0 {
return
}
sc.Sort()
fmt.Printf("Avg %s speed: %s/s\n", msg, prettyByteSize(int64(MEBIBYTE/sc.Mean())))
fmt.Printf("P1 %s speed: %s/s\n", msg, prettyByteSize(int64(MEBIBYTE/sc.Quantile(0.99))))
fmt.Printf("P10 %s speed: %s/s\n", msg, prettyByteSize(int64(MEBIBYTE/sc.Quantile(0.9))))
}
func prettyByteSize(b int64) string {
bf := float64(b)
for _, unit := range []string{"", "Ki", "Mi", "Gi", "Ti"} {
if math.Abs(bf) < 1024.0 {
return fmt.Sprintf("%3.1f %sB", bf, unit)
}
bf /= 1024.0
}
return fmt.Sprintf("%.1f PiB", bf)
}