-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathbitset_test.go
72 lines (58 loc) · 1.56 KB
/
bitset_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package main
import (
"testing"
"github.com/RoaringBitmap/roaring"
"github.com/willf/bitset"
)
func BenchmarkBitsetRoaringConsecutive1000(b *testing.B) {
benchmarkBitsetRoaringConsecutive(b, 1000)
}
func BenchmarkBitsetWillfConsecutive1000(b *testing.B) {
benchmarkBitsetWillfConsecutive(b, 1000)
}
func BenchmarkBitsetRoaringConsecutive10000(b *testing.B) {
benchmarkBitsetRoaringConsecutive(b, 10000)
}
func BenchmarkBitsetWillfConsecutive10000(b *testing.B) {
benchmarkBitsetWillfConsecutive(b, 10000)
}
func BenchmarkBitsetRoaringConsecutive100000(b *testing.B) {
benchmarkBitsetRoaringConsecutive(b, 100000)
}
func BenchmarkBitsetWillfConsecutive100000(b *testing.B) {
benchmarkBitsetWillfConsecutive(b, 100000)
}
func BenchmarkBitsetRoaringConsecutive1000000(b *testing.B) {
benchmarkBitsetRoaringConsecutive(b, 1000000)
}
func BenchmarkBitsetWillfConsecutive1000000(b *testing.B) {
benchmarkBitsetWillfConsecutive(b, 1000000)
}
func benchmarkBitsetRoaringConsecutive(b *testing.B, end uint32) {
for i := 0; i < b.N; i++ {
rb := roaring.NewBitmap()
for i := uint32(0); i < end; i++ {
rb.Add(i)
}
}
}
func benchmarkBitsetWillfConsecutive(b *testing.B, end uint) {
for i := 0; i < b.N; i++ {
b := bitset.New(end)
for i := uint(0); i < end; i++ {
b.Set(i)
}
}
}
// func benchmarkBitsetRoaringRandom(nums []uint32) {
// rb := roaring.NewBitmap()
// for _, num := range nums {
// rb.Add(num)
// }
// }
// func benchmarkBitsetWillfRandom(nums []uint) {
// b := bitset.New(len(nums))
// for _, num := range nums {
// b.Set(num)
// }
// }