BENCHMARKS, to run them type "go test -bench Benchmark -run -" go test -bench BenchmarkIteratorAlloc -benchmem -run -
(b *testing.B)
| 16 | |
| 17 | // go test -bench BenchmarkIteratorAlloc -benchmem -run - |
| 18 | func 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() |
nothing calls this directly
no test coverage detected
searching dependent graphs…