Skip to content

Commit

Permalink
Add error calculation to morris
Browse files Browse the repository at this point in the history
  • Loading branch information
fluhus committed Mar 31, 2024
1 parent 0d8e780 commit 9af09b9
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
38 changes: 38 additions & 0 deletions morris/error/error.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Prints error rates of Morris counter using different m's.
package main

import (
"fmt"

"github.com/fluhus/gostuff/gnum"
"github.com/fluhus/gostuff/morris"
"github.com/fluhus/gostuff/ptimer"
)

const (
upto = 10000000
reps = 100
)

func main() {
ms := []uint{1, 3, 10, 30, 100, 300, 1000, 3000, 10000}
var errs []float64
for _, m := range ms {
pt := ptimer.NewMessage(fmt.Sprint("{} (", m, ")"))
err := 0.0
for rep := 1; rep <= reps; rep++ {
c := uint(0)
for i := 1; i <= upto; i++ {
c = morris.Raise(c, m)
r := morris.Restore(c, m)
err += float64(gnum.Abs(int(i)-int(r))) / float64(i)
pt.Inc()
}
}
pt.Done()
errs = append(errs, err/upto/reps)
}
for i := range ms {
fmt.Printf("// % 10d: %.1f%%\n", ms[i], errs[i]*100)
}
}
14 changes: 14 additions & 0 deletions morris/morris.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,20 @@
// A single counter should use the same m for all calls to Raise and Restore.
//
// This package is experimental.
//
// # Error rates
//
// Average error rates for different values of m:
//
// 1: 54.2%
// 3: 31.1%
// 10: 15.5%
// 30: 8.8%
// 100: 4.6%
// 300: 2.5%
// 1000: 1.6%
// 3000: 0.9%
// 10000: 0.5%
package morris

import (
Expand Down

0 comments on commit 9af09b9

Please sign in to comment.