forked from zaiyunduan123/Java-Summarize
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBloomFiltersTest.java
More file actions
71 lines (57 loc) · 2.13 KB
/
BloomFiltersTest.java
File metadata and controls
71 lines (57 loc) · 2.13 KB
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
package interview.algorithm;
import org.junit.Assert;
import org.junit.Test;
import java.util.HashSet;
/**
* 如何判断一个元素在亿级数据中是否存在?
* <p>
* 为了方便调试加入了 GC 日志的打印,以及内存溢出后 Dump 内存。
* -Xms64m -Xmx64m -XX:+PrintHeapAtGC -XX:+HeapDumpOnOutOfMemoryError
*/
public class BloomFiltersTest {
@Test
public void hashMapTest() {
long start = System.currentTimeMillis();
HashSet<Integer> hashSet = new HashSet<>(10000000);
for (int i = 0; i < 10000000; i++) {
hashSet.add(i);
}
Assert.assertTrue(hashSet.contains(1));
Assert.assertTrue(hashSet.contains(2));
Assert.assertTrue(hashSet.contains(3));
long end = System.currentTimeMillis();
System.out.println("执行时间:" + (end - start));
}
@Test
public void bloomFilterTest() {
long start = System.currentTimeMillis();
BloomFilters bloomFilters = new BloomFilters(10000000);
for (int i = 0; i < 10000000; i++) {
bloomFilters.add(i + "");
}
Assert.assertTrue(bloomFilters.check(1 + ""));
Assert.assertTrue(bloomFilters.check(2 + ""));
Assert.assertTrue(bloomFilters.check(3 + ""));
Assert.assertTrue(bloomFilters.check(999999 + ""));
Assert.assertFalse(bloomFilters.check(400230340 + ""));
long end = System.currentTimeMillis();
System.out.println("执行时间:" + (end - start));
}
@Test
public void guavaTest() {
long star = System.currentTimeMillis();
/* BloomFilter<Integer> filter = BloomFilter.create(
Funnels.integerFunnel(),
10000000,
0.01);
for (int i = 0; i < 10000000; i++) {
filter.put(i);
}
Assert.assertTrue(filter.mightContain(1));
Assert.assertTrue(filter.mightContain(2));
Assert.assertTrue(filter.mightContain(3));
Assert.assertFalse(filter.mightContain(10000000));*/
long end = System.currentTimeMillis();
System.out.println("执行时间:" + (end - star));
}
}