MCPcopy
hub / github.com/RoaringBitmap/roaring / BenchmarkNexts

Function BenchmarkNexts

benchmark_test.go:931–983  ·  view source on GitHub ↗

go test -bench BenchmarkNexts -benchmem -run -

(b *testing.B)

Source from the content-addressed store, hash-verified

929
930// go test -bench BenchmarkNexts -benchmem -run -
931func BenchmarkNexts(b *testing.B) {
932
933 for _, gap := range []uint32{1, 2, 4, 8, 16, 32, 64, 256, 1024, 8096} {
934
935 rrs := make([]uint32, 500000)
936 v := uint32(0)
937 for i := range rrs {
938 rrs[i] = v
939 v += gap
940 }
941
942 bm := NewBitmap()
943 bm.AddMany(rrs)
944
945 var totnext uint64
946 var totnextmany uint64
947
948 density := float32(100) / float32(gap)
949
950 densityStr := fmt.Sprintf("__%f%%", density)
951
952 b.Run("next"+densityStr, func(b *testing.B) {
953 for n := 0; n < b.N; n++ {
954 totnext = 0
955 iter := bm.Iterator()
956 for iter.HasNext() {
957 v := iter.Next()
958 totnext += uint64(v)
959 }
960 }
961 b.StopTimer()
962 })
963
964 b.Run("nextmany"+densityStr, func(b *testing.B) {
965 for n := 0; n < b.N; n++ {
966 totnextmany = 0
967 iter := bm.ManyIterator()
968 // worst case, in practice will reuse buffers across many roars
969 buf := make([]uint32, 4096)
970 for j := iter.NextMany(buf); j != 0; j = iter.NextMany(buf) {
971 for i := 0; i < j; i++ {
972 totnextmany += uint64(buf[i])
973 }
974 }
975 }
976 b.StopTimer()
977 })
978
979 if totnext != totnextmany {
980 b.Fatalf("Cardinalities don't match: %d, %d", totnext, totnextmany)
981 }
982 }
983}
984
985// go test -bench BenchmarkRLENexts -benchmem -run -
986func BenchmarkNextsRLE(b *testing.B) {

Callers

nothing calls this directly

Calls 7

AddManyMethod · 0.95
IteratorMethod · 0.95
ManyIteratorMethod · 0.95
NewBitmapFunction · 0.70
HasNextMethod · 0.65
NextMethod · 0.65
NextManyMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…