github.com/fluhus/gostuff@v0.4.1-0.20240331134726-be71864f2b5d/morris/error/error.go (about) 1 // Prints error rates of Morris counter using different m's. 2 package main 3 4 import ( 5 "fmt" 6 7 "github.com/fluhus/gostuff/gnum" 8 "github.com/fluhus/gostuff/morris" 9 "github.com/fluhus/gostuff/ptimer" 10 ) 11 12 const ( 13 upto = 10000000 14 reps = 100 15 ) 16 17 func main() { 18 ms := []uint{1, 3, 10, 30, 100, 300, 1000, 3000, 10000} 19 var errs []float64 20 for _, m := range ms { 21 pt := ptimer.NewMessage(fmt.Sprint("{} (", m, ")")) 22 err := 0.0 23 for rep := 1; rep <= reps; rep++ { 24 c := uint(0) 25 for i := 1; i <= upto; i++ { 26 c = morris.Raise(c, m) 27 r := morris.Restore(c, m) 28 err += float64(gnum.Abs(int(i)-int(r))) / float64(i) 29 pt.Inc() 30 } 31 } 32 pt.Done() 33 errs = append(errs, err/upto/reps) 34 } 35 for i := range ms { 36 fmt.Printf("// % 10d: %.1f%%\n", ms[i], errs[i]*100) 37 } 38 }