/
bloom_test.go
126 lines (107 loc) · 2.12 KB
/
bloom_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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package goestimators
import (
"fmt"
"testing"
)
func TestBloom256(t *testing.T) {
var N uint64 = 100
b := NewBloom(Size256)
var i uint64
buf := make([]byte, 8)
for i = 0; i < N; i++ {
uint64ToBytes(i, buf)
//fmt.Println(i, buf)
b.Add(buf)
}
notfound := 0
for i = 0; i < N+10; i++ {
uint64ToBytes(i, buf)
if !b.Check(buf) {
notfound++
}
}
fmt.Println("false.prob:", b.FalsePositiveProbability(N), "notfound.256:", notfound)
if notfound > 0 {
t.Log("Integers in range ", N, " not found:", notfound)
}
}
func TestBloom65536(t *testing.T) {
var N uint64 = 30000
b := NewBloom(Size65536)
var i uint64
buf := make([]byte, 8)
for i = 0; i < N; i++ {
uint64ToBytes(i, buf)
//fmt.Println(i, buf)
b.Add(buf)
}
notfound := 0
for i = 0; i < N+10; i++ {
uint64ToBytes(i, buf)
if !b.Check(buf) {
notfound++
}
}
fmt.Println("false.prob:", b.FalsePositiveProbability(N), "notfound.65536:", notfound)
if notfound > 0 {
t.Log("Integers in range ", N, " not found:", notfound)
}
}
func BenchmarkBloomObserve256(b *testing.B) {
b.StopTimer()
bl := NewBloom(Size256)
b.StartTimer()
var i uint64
buf := make([]byte, 8)
for i = 0; i < uint64(b.N); i++ {
uint64ToBytes(i, buf)
bl.Observe(buf)
}
}
func BenchmarkBloomCheck256(b *testing.B) {
b.StopTimer()
bl := NewBloom(Size256)
var i uint64
buf := make([]byte, 8)
for i = 0; i < uint64(b.N); i++ {
uint64ToBytes(i, buf)
bl.Observe(buf)
}
b.StartTimer()
notfound := 0
for i = 0; i < uint64(b.N)+10; i++ {
uint64ToBytes(i, buf)
if !bl.Check(buf) {
notfound++
}
}
}
func BenchmarkBloomObserve65536(b *testing.B) {
b.StopTimer()
bl := NewBloom(Size65536)
b.StartTimer()
var i uint64
buf := make([]byte, 8)
for i = 0; i < uint64(b.N); i++ {
uint64ToBytes(i, buf)
bl.Observe(buf)
}
}
func BenchmarkBloomCheck65536(b *testing.B) {
b.StopTimer()
bl := NewBloom(Size65536)
var i uint64
buf := make([]byte, 8)
for i = 0; i < uint64(b.N); i++ {
uint64ToBytes(i, buf)
bl.Observe(buf)
}
b.StartTimer()
notfound := 0
for i = 0; i < uint64(b.N)+10; i++ {
uint64ToBytes(i, buf)
if !bl.Check(buf) {
notfound++
}
}
}