MCPcopy Index your code
hub / github.com/RoaringBitmap/roaring / BenchmarkUnionInPlaceCopyOnWrite

Function BenchmarkUnionInPlaceCopyOnWrite

benchmark_test.go:350–389  ·  view source on GitHub ↗

BenchmarkUnionInPlaceCopyOnWrite tests the performance of bitmap.Or() when the bitmap was generated via FromBuffer. In this case all left containers need to be copied in order to be updated. The nested for-loops test a number of different scenarios with respect to the ranges and densities of bitmaps

(b *testing.B)

Source from the content-addressed store, hash-verified

348// The nested for-loops test a number of different scenarios
349// with respect to the ranges and densities of bitmaps.
350func BenchmarkUnionInPlaceCopyOnWrite(b *testing.B) {
351 // uint32s to maintain 1.12 compatibility, which requires unsigned shifts.
352 startingContainerPower := uint32(4)
353 finalContainerPower := uint32(10)
354 containerIncrement := uint32(3)
355 startingItemsPower := uint32(3)
356 finalItemsPower := uint32(10)
357 itemsIncrement := uint32(7)
358 for leftContainerPower := startingContainerPower; leftContainerPower <= finalContainerPower; leftContainerPower += containerIncrement {
359 for rightContainerPower := startingContainerPower; rightContainerPower <= finalContainerPower; rightContainerPower += containerIncrement {
360 for leftItemsPerContainerPower := startingItemsPower; leftItemsPerContainerPower <= finalItemsPower; leftItemsPerContainerPower += itemsIncrement {
361 for rightItemsPerContainerPower := startingItemsPower; rightItemsPerContainerPower <= finalItemsPower; rightItemsPerContainerPower += itemsIncrement {
362 b.Run(fmt.Sprintf("%d-%d-%d-%d", leftContainerPower, rightContainerPower, leftItemsPerContainerPower, rightItemsPerContainerPower),
363 func(b *testing.B) {
364 leftMax := (1 << 16) << leftContainerPower
365 rightMax := (1 << 16) << rightContainerPower
366 leftItems := 1 << (leftContainerPower + leftItemsPerContainerPower)
367 rightItems := 1 << (rightContainerPower + rightItemsPerContainerPower)
368 left := make([][]byte, 10)
369 right := make([]*Bitmap, 10)
370 for i := 0; i < 10; i++ {
371 right[i] = NewBitmap()
372 left[i] = generateRandomBitmap(b, leftMax, leftItems)
373 _, err := right[i].FromBuffer(generateRandomBitmap(b, rightMax, rightItems))
374 require.NoError(b, err)
375 }
376 // This tests a destructive operation, Or() so have to have a fresh bitmap per test.
377 targetLefts := make([]*Bitmap, b.N)
378 for i := 0; i < b.N; i++ {
379 targetLefts[i] = NewBitmap()
380 _, err := targetLefts[i].FromBuffer(left[i%10])
381 require.NoError(b, err)
382 }
383 runActualBenchmark(b, targetLefts, right)
384 })
385 }
386 }
387 }
388 }
389}
390
391// runActualBenchmark is broken out primarily so you can profile the tests,
392// as otherwise the generation overwhelms the actual test.

Callers

nothing calls this directly

Calls 4

generateRandomBitmapFunction · 0.85
runActualBenchmarkFunction · 0.85
FromBufferMethod · 0.80
NewBitmapFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…