Skip to content

Instantly share code, notes, and snippets.

@trygenericdev
Last active August 29, 2015 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trygenericdev/ca64d83e193bbc2cb3ff to your computer and use it in GitHub Desktop.
Save trygenericdev/ca64d83e193bbc2cb3ff to your computer and use it in GitHub Desktop.
BenchmarkRollsum
func BenchmarkRollsum(b *testing.B) {
const bufSize = 5 << 20
buf := make([]byte, bufSize)
for i := range buf {
buf[i] = byte(rand.Int63())
}
b.ResetTimer()
rs := New()
splits := 0
for i := 0; i < b.N; i++ {
splits = 0
for _, b := range buf {
rs.Roll(b)
if rs.OnSplit() {
_ = rs.Bits()
splits++
}
}
}
b.SetBytes(bufSize)
b.Logf("num splits = %d; every %d bytes", splits, int(float64(bufSize)/float64(splits)))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment