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

Function BenchmarkIteratorAlloc

benchmark_test.go:18–144  ·  view source on GitHub ↗

BENCHMARKS, to run them type "go test -bench Benchmark -run -" go test -bench BenchmarkIteratorAlloc -benchmem -run -

(b *testing.B)

Source from the content-addressed store, hash-verified

16
17// go test -bench BenchmarkIteratorAlloc -benchmem -run -
18func BenchmarkIteratorAlloc(b *testing.B) {
19 bm := NewBitmap()
20 domain := 100000000
21 count := 10000
22 for j := 0; j < count; j++ {
23 v := uint32(rand.Intn(domain))
24 bm.Add(v)
25 }
26 i := IntIterator{}
27 expectedCardinality := bm.GetCardinality()
28 counter := uint64(0)
29 b.Run("simple iteration with alloc", func(b *testing.B) {
30 for n := 0; n < b.N; n++ {
31 counter = 0
32 i := bm.Iterator()
33 for i.HasNext() {
34 i.Next()
35 counter++
36 }
37 }
38 b.StopTimer()
39 })
40 if counter != expectedCardinality {
41 b.Fatalf("Cardinalities don't match: %d, %d", counter, expectedCardinality)
42 }
43 b.Run("simple iteration", func(b *testing.B) {
44 for n := 0; n < b.N; n++ {
45 counter = 0
46 i.Initialize(bm)
47 for i.HasNext() {
48 i.Next()
49 counter++
50 }
51 }
52 b.StopTimer()
53 })
54 if counter != expectedCardinality {
55 b.Fatalf("Cardinalities don't match: %d, %d", counter, expectedCardinality)
56 }
57 b.Run("values iteration", func(b *testing.B) {
58 for n := 0; n < b.N; n++ {
59 counter = 0
60 Values(bm)(func(_ uint32) bool {
61 counter++
62 return true
63 })
64 }
65 b.StopTimer()
66 })
67 if counter != expectedCardinality {
68 b.Fatalf("Cardinalities don't match: %d, %d", counter, expectedCardinality)
69 }
70 b.Run("reverse iteration with alloc", func(b *testing.B) {
71 for n := 0; n < b.N; n++ {
72 counter = 0
73 ir := bm.ReverseIterator()
74 for ir.HasNext() {
75 ir.Next()

Callers

nothing calls this directly

Calls 12

AddMethod · 0.95
GetCardinalityMethod · 0.95
IteratorMethod · 0.95
ReverseIteratorMethod · 0.95
ManyIteratorMethod · 0.95
NewBitmapFunction · 0.70
ValuesFunction · 0.70
BackwardFunction · 0.70
HasNextMethod · 0.65
NextMethod · 0.65
NextManyMethod · 0.65
InitializeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…