From 1ef45879138342ba82d7f53f4d7fc071224ac515 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Fri, 22 Aug 2014 15:50:25 -0700 Subject: [PATCH] rollsum: don't benchmark the Rand function Change-Id: Ibed1864d3b4c57eb3684c7208610da7015b6365d --- pkg/rollsum/rollsum_test.go | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) 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))) }