go test -bench BenchmarkNexts -benchmem -run -
(b *testing.B)
| 929 | |
| 930 | // go test -bench BenchmarkNexts -benchmem -run - |
| 931 | func 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 - |
| 986 | func BenchmarkNextsRLE(b *testing.B) { |
nothing calls this directly
no test coverage detected
searching dependent graphs…