Add stats test and print observation count

Signed-off-by: Jakub Sztandera <kubuxu@protocol.ai>
This commit is contained in:
Jakub Sztandera 2020-06-27 14:39:42 +02:00
parent 1bc9fbca20
commit a6417dc24b
No known key found for this signature in database
GPG Key ID: 9A9AF56F8B3879BA
2 changed files with 27 additions and 1 deletions

View File

@ -434,7 +434,7 @@ var importAnalyzeCmd = &cli.Command{
sort.Strings(keys)
for _, k := range keys {
s := charges[k]
fmt.Printf("%s: incr by %f (%f)\n", k, s.mean, math.Sqrt(s.variance()))
fmt.Printf("%s: incr by %f (stddev: %f, count: %f)\n", k, s.mean, math.Sqrt(s.variance()), s.count)
}
sort.Slice(invocs, func(i, j int) bool {

View File

@ -0,0 +1,26 @@
package main
import (
"math"
"math/rand"
"testing"
)
func TestStats(t *testing.T) {
N := 16
ss := make([]*stats, N)
for i := 0; i < N; i++ {
ss[i] = &stats{}
maxJ := rand.Intn(1000)
for j := 0; j < maxJ; j++ {
ss[i].AddPoint(rand.NormFloat64()*5 + 500)
ss[i].AddPoint(rand.NormFloat64()*5 + 1000)
}
t.Logf("mean: %f, stddev: %f, count %f", ss[i].mean, math.Sqrt(ss[i].variance()), ss[i].count)
}
out := &stats{}
for i := 0; i < N; i++ {
out.Combine(ss[i])
t.Logf("combine: mean: %f, stddev: %f", out.mean, math.Sqrt(out.variance()))
}
}