Skip to content

Commit

Permalink
Cleaning new benchmarks.
Browse files Browse the repository at this point in the history
  • Loading branch information
lemire committed Aug 17, 2018
1 parent 87ba24d commit 59d8967
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 62 deletions.
5 changes: 2 additions & 3 deletions bitset.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,11 +280,10 @@ func (b *BitSet) NextSetMany(i uint, buffer []uint) (uint, []uint) {
word = word ^ t
}
for idx, word := range b.set[x+1:] {
//base += 64
for word != 0 {
r := trailingZeroes64(word)
t := word & ((^word) + 1)
myanswer[size] = r + uint(x + idx + 1) * 64 //base
myanswer[size] = r + uint(x+idx+1)*64
size++
if size == capacity {
goto End
Expand All @@ -300,7 +299,7 @@ End:
}
}

func (b *BitSet) NextSetManyold(i uint, buffer []uint) (uint, []uint) {
func (b *BitSet) NextSetManyoldold(i uint, buffer []uint) (uint, []uint) {
myanswer := buffer[:0]
x := int(i >> log2WordSize)
if x >= len(b.set) {
Expand Down
113 changes: 54 additions & 59 deletions bitset_benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,10 @@ func BenchmarkFlorianUekermannIterateMany(b *testing.B) {
var input = make([]uint64, 68)
setRnd(input, 4)
var bitmap = From(input)
buffer := make([]uint, 256)
b.ResetTimer()
var checksum = uint(0)
for i := 0; i < b.N; i++ {
buffer := make([]uint, 256)
var last, batch = bitmap.NextSetMany(0, buffer)
for len(batch) > 0 {
for _, idx := range batch {
Expand All @@ -211,33 +212,13 @@ func BenchmarkFlorianUekermannIterateMany(b *testing.B) {
return
}
}
// go test -bench=BenchmarkFlorianUekermannIterateMany
func BenchmarkFlorianUekermannIterateManyold(b *testing.B) {
var input = make([]uint64, 68)
setRnd(input, 4)
var bitmap = From(input)
buffer := make([]uint, 256)
b.ResetTimer()
for i := 0; i < b.N; i++ {
var last, batch = bitmap.NextSetManyold(0, buffer)
for len(batch) > 0 {
for _, idx := range batch {
checksum += idx
}
last, batch = bitmap.NextSetManyold(last+1, batch)
}
}
if checksum == 0 { // added just to fool ineffassign
return
}
}


func BenchmarkFlorianUekermannIterateManyReg(b *testing.B) {
var input = make([]uint64, 68)
setRnd(input, 4)
var bitmap = From(input)
b.ResetTimer()
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
Expand Down Expand Up @@ -266,6 +247,7 @@ 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)
}
Expand All @@ -284,6 +266,7 @@ func BenchmarkFlorianUekermannLowDensityIterateMany(b *testing.B) {
var bitmap = From(input)
buffer := make([]uint, 256)
b.ResetTimer()
var checksum = uint(0)
for i := 0; i < b.N; i++ {
var last, batch = bitmap.NextSetMany(0, buffer)
for len(batch) > 0 {
Expand All @@ -298,31 +281,6 @@ func BenchmarkFlorianUekermannLowDensityIterateMany(b *testing.B) {
}
}

// go test -bench=BenchmarkFlorianUekermannLowDensityIterateMany
func BenchmarkFlorianUekermannLowDensityIterateManyold(b *testing.B) {
var input = make([]uint64, 1000000)
var rnd = rand.NewSource(0).(rand.Source64)
for i := 0; i < 50000; i++ {
input[rnd.Uint64()%1000000] = 1
}
var bitmap = From(input)
buffer := make([]uint, 256)

b.ResetTimer()
for i := 0; i < b.N; i++ {
var last, batch = bitmap.NextSetManyold(0, buffer)
for len(batch) > 0 {
for _, idx := range batch {
checksum += idx
}
last, batch = bitmap.NextSetManyold(last+1, batch)
}
}
if checksum == 0 { // added just to fool ineffassign
return
}
}

func BenchmarkFlorianUekermannLowDensityIterateManyReg(b *testing.B) {
var input = make([]uint64, 1000000)
var rnd = rand.NewSource(0).(rand.Source64)
Expand All @@ -331,6 +289,7 @@ func BenchmarkFlorianUekermannLowDensityIterateManyReg(b *testing.B) {
}
var bitmap = From(input)
b.ResetTimer()
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
Expand All @@ -348,6 +307,7 @@ func BenchmarkFlorianUekermannLowDensityIterateManyComp(b *testing.B) {
input[rnd.Uint64()%1000000] = 1
}
b.ResetTimer()
var checksum = uint(0)
for i := 0; i < b.N; i++ {
checksum += good(input)
}
Expand All @@ -356,8 +316,6 @@ func BenchmarkFlorianUekermannLowDensityIterateManyComp(b *testing.B) {
}
}



// go test -bench=BenchmarkFlorianUekermannLowDensityIterateMany
func BenchmarkFlorianUekermannMidDensityIterateMany(b *testing.B) {
var input = make([]uint64, 10000)
Expand All @@ -369,6 +327,7 @@ func BenchmarkFlorianUekermannMidDensityIterateMany(b *testing.B) {
buffer := make([]uint, 256)

b.ResetTimer()
var checksum = uint(0)
for i := 0; i < b.N; i++ {
var last, batch = bitmap.NextSetMany(0, buffer)
for len(batch) > 0 {
Expand All @@ -383,38 +342,75 @@ func BenchmarkFlorianUekermannMidDensityIterateMany(b *testing.B) {
}
}

// go test -bench=BenchmarkFlorianUekermannLowDensityIterateMany
func BenchmarkFlorianUekermannMidDensityIterateManyold(b *testing.B) {
func BenchmarkFlorianUekermannMidDensityIterateManyReg(b *testing.B) {
var input = make([]uint64, 10000)
var rnd = rand.NewSource(0).(rand.Source64)
for i := 0; i < 30000; i++ {
input[rnd.Uint64()%10000] |= 1 << rnd.Uint64()
}
var bitmap = From(input)
b.ResetTimer()
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
}
}
if checksum == 0 { // added just to fool ineffassign
return
}
}

func BenchmarkFlorianUekermannMidDensityIterateManyComp(b *testing.B) {
var input = make([]uint64, 10000)
var rnd = rand.NewSource(0).(rand.Source64)
for i := 0; i < 30000; i++ {
input[rnd.Uint64()%10000] |= 1 << rnd.Uint64()
}
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
}
}

func BenchmarkFlorianUekermannMidStrongDensityIterateMany(b *testing.B) {
var input = make([]uint64, 10000)
var rnd = rand.NewSource(0).(rand.Source64)
for i := 0; i < 200000; i++ {
input[rnd.Uint64()%10000] |= 1 << rnd.Uint64()
}
var bitmap = From(input)
buffer := make([]uint, 256)

b.ResetTimer()
var checksum = uint(0)
for i := 0; i < b.N; i++ {
var last, batch = bitmap.NextSetManyold(0, buffer)
var last, batch = bitmap.NextSetMany(0, buffer)
for len(batch) > 0 {
for _, idx := range batch {
checksum += idx
}
last, batch = bitmap.NextSetManyold(last+1, batch)
last, batch = bitmap.NextSetMany(last+1, batch)
}
}
if checksum == 0 { // added just to fool ineffassign
return
}
}

func BenchmarkFlorianUekermannMidDensityIterateManyReg(b *testing.B) {
func BenchmarkFlorianUekermannMidStrongDensityIterateManyReg(b *testing.B) {
var input = make([]uint64, 10000)
var rnd = rand.NewSource(0).(rand.Source64)
for i := 0; i < 30000; i++ {
for i := 0; i < 200000; i++ {
input[rnd.Uint64()%10000] |= 1 << rnd.Uint64()
}
var bitmap = From(input)
b.ResetTimer()
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
Expand All @@ -425,19 +421,18 @@ func BenchmarkFlorianUekermannMidDensityIterateManyReg(b *testing.B) {
}
}

func BenchmarkFlorianUekermannMidDensityIterateManyComp(b *testing.B) {
func BenchmarkFlorianUekermannMidStrongDensityIterateManyComp(b *testing.B) {
var input = make([]uint64, 10000)
var rnd = rand.NewSource(0).(rand.Source64)
for i := 0; i < 30000; i++ {
for i := 0; i < 200000; i++ {
input[rnd.Uint64()%10000] |= 1 << rnd.Uint64()
}
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
}
}

var checksum = uint(0)

0 comments on commit 59d8967

Please sign in to comment.