diff --git a/pkg/rollsum/rollsum_test.go b/pkg/rollsum/rollsum_test.go index 37ed8cdc3..edd4cff02 100644 --- a/pkg/rollsum/rollsum_test.go +++ b/pkg/rollsum/rollsum_test.go @@ -55,19 +55,25 @@ func TestSum(t *testing.T) { } func BenchmarkRollsum(b *testing.B) { - bytesSize := int64(1024 * 1024 * 5) + 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 j := int64(0); j < bytesSize; j++ { - rs.Roll(byte(rand.Int63() & 0xff)) + for _, b := range buf { + rs.Roll(b) if rs.OnSplit() { _ = rs.Bits() splits++ } } } - b.SetBytes(bytesSize) - b.Logf("num splits = %d; every %d bytes", splits, int(float64(bytesSize)/float64(splits))) + b.SetBytes(bufSize) + b.Logf("num splits = %d; every %d bytes", splits, int(float64(bufSize)/float64(splits))) }