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

Function BenchmarkAndNot

benchmark_test.go:1208–1306  ·  view source on GitHub ↗
(b *testing.B)

Source from the content-addressed store, hash-verified

1206}
1207
1208func BenchmarkAndNot(b *testing.B) {
1209 type generator struct {
1210 name string
1211 f func() *Bitmap
1212 }
1213 makeRunContainer := generator{
1214 name: "run",
1215 f: func() *Bitmap {
1216 rb := NewBitmap()
1217 for i := 0; i < 100; i++ {
1218 start := rand.Intn(math.MaxUint16)
1219 limit := start + rand.Intn(math.MaxUint16-start)
1220 rb.AddRange(uint64(start), uint64(limit))
1221 }
1222 rb.RunOptimize()
1223 return rb
1224 },
1225 }
1226
1227 makeArrayContainer := generator{
1228 name: "array",
1229 f: func() *Bitmap {
1230 rb := NewBitmap()
1231 for i := 0; i < arrayDefaultMaxSize/2; i++ {
1232 rb.Add(uint32(rand.Intn(math.MaxUint16)))
1233 }
1234 return rb
1235 },
1236 }
1237 makeBitmapContainer := generator{
1238 name: "bitmap",
1239 f: func() *Bitmap {
1240 buf := make([]uint64, 1024)
1241 for i := range buf {
1242 buf[i] = rand.Uint64()
1243 }
1244
1245 return FromDense(buf, false)
1246 },
1247 }
1248
1249 for _, inPlace := range []bool{true, false} {
1250 b.Run(fmt.Sprintf("inPlace=%v", inPlace), func(b *testing.B) {
1251 for _, leftGen := range []generator{makeRunContainer, makeArrayContainer, makeBitmapContainer} {
1252 b.Run(fmt.Sprintf("left=%s", leftGen.name), func(b *testing.B) {
1253 for _, rightGen := range []generator{makeRunContainer, makeArrayContainer, makeBitmapContainer} {
1254 b.Run(fmt.Sprintf("right=%s", rightGen.name), func(b *testing.B) {
1255 b.ReportAllocs()
1256 b.StopTimer()
1257 serializedLefts := make([][]byte, 1000)
1258 for i := range serializedLefts {
1259 var err error
1260 serializedLefts[i], err = leftGen.f().ToBytes()
1261 if err != nil {
1262 b.Fatal(err)
1263 }
1264 }
1265 serializedRights := make([][]byte, 1000)

Callers

nothing calls this directly

Calls 10

AddRangeMethod · 0.95
RunOptimizeMethod · 0.95
AddMethod · 0.95
FromDenseFunction · 0.85
FromBufferMethod · 0.80
NewBitmapFunction · 0.70
AndNotFunction · 0.70
ToBytesMethod · 0.45
CloneMethod · 0.45
AndNotMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…