From 4ec4abbcdecb653afbfd6c9a612a134a8b20808a Mon Sep 17 00:00:00 2001 From: Daniel Lemire Date: Fri, 17 Aug 2018 15:28:05 -0400 Subject: [PATCH] Format. --- bitset.go | 2 +- bitset_benchmark_test.go | 31 +++++++++++++++++++++++++++++-- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/bitset.go b/bitset.go index c187395..800e01b 100644 --- a/bitset.go +++ b/bitset.go @@ -263,7 +263,7 @@ func (b *BitSet) NextSetMany(i uint, buffer []uint) (uint, []uint) { return 0, myanswer } w := b.set[x] - skip := i & (wordSize - 1) + skip := i & (wordSize - 1) w = (w >> skip) << skip base := uint(x << 6) capacity := cap(buffer) diff --git a/bitset_benchmark_test.go b/bitset_benchmark_test.go index 39ee722..a2c8f48 100644 --- a/bitset_benchmark_test.go +++ b/bitset_benchmark_test.go @@ -197,7 +197,7 @@ func BenchmarkFlorianUekermannIterateMany(b *testing.B) { setRnd(input, 4) var bitmap = From(input) b.ResetTimer() - var checksum = uint(0) + var checksum = uint(0) for i := 0; i < b.N; i++ { buffer := make([]uint, 256) var last, batch = bitmap.NextSetMany(0, buffer) @@ -218,7 +218,7 @@ func BenchmarkFlorianUekermannIterateManyReg(b *testing.B) { setRnd(input, 4) var bitmap = From(input) b.ResetTimer() - var checksum = uint(0) + var checksum = uint(0) for i := 0; i < b.N; i++ { for j, e := bitmap.NextSet(0); e; j, e = bitmap.NextSet(j + 1) { checksum += j @@ -228,3 +228,30 @@ func BenchmarkFlorianUekermannIterateManyReg(b *testing.B) { return } } + +func good(set []uint64) (checksum uint) { + for wordIdx, word := range set { + var wordIdx = uint(wordIdx * 64) + for word != 0 { + var bitIdx = uint(trailingZeroes64(word)) + word ^= 1 << bitIdx + // Do something with the result of the next line + var index = wordIdx + bitIdx + checksum += index + } + } + return checksum +} + +func BenchmarkFlorianUekermannIterateManyComp(b *testing.B) { + var input = make([]uint64, 68) + setRnd(input, 4) + b.ResetTimer() + var checksum = uint(0) + for i := 0; i < b.N; i++ { + checksum += good(input) + } + if checksum == 0 { // added just to fool ineffassign + return + } +}