Skip to content

Commit 0e85974

Browse files
committed
Merge branch 'master' of github.com:FastFilter/fastfilter_cpp into HEAD
2 parents f9c32cf + 6124611 commit 0e85974

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+6653
-326
lines changed

README.md

Lines changed: 87 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,113 @@
11
# fastfilter_cpp
2+
23
Fast Filter: Fast approximate membership filter implementations (C++)
34

4-
This is a research library, developers might want to consider our [Header-only Xor Filter library in C](https://github.com/FastFilter/xor_singleheader/).
5+
This is a research library currently. It is not meant for production use.
6+
7+
Developers might want to consider our [Header-only Xor Filter library in C](https://github.com/FastFilter/xor_singleheader/).
8+
9+
Reference: [Xor Filters: Faster and Smaller Than Bloom and Cuckoo Filters](https://arxiv.org/abs/1912.08258), Journal of Experimental Algorithmics (to appear).
10+
11+
512

613
## Prerequisites
714

815
- A C++11 compiler such as GNU G++ or LLVM Clang++
9-
- Make
16+
- Make
1017

18+
Expectations:
1119

20+
- Though it should be possible to run this benchmark on any operating system, we expect Linux and use its performance counters to measure performance.
21+
- We expect an x64 processor with AVX2 support though most filters work on any processor, if you compile on a machine that does not support AVX2 instructions, the corresponding filters that depend on AVX2 will be disabled.
1222

1323
## Usage
1424

25+
Make sure to select the right GNU GCC compiler (e.g., via `export export CXX=g++-8`).
26+
You may want to disable hyperthreading and adjust page sizes. Run the benchmark
27+
on a quiet machine.
28+
29+
1530
```
31+
git clone https://github.com/FastFilter/fastfilter_cpp.git
32+
cd fastfilter_cpp
1633
cd benchmarks
1734
make
35+
# there may be compiler warnings at this point, we compile with '-Wall'
1836
./bulk-insert-and-query.exe 10000000
37+
# collect the output (it is quite verbose)
38+
./bulk-insert-and-query.exe 100000000
39+
```
40+
41+
Your results will depend on the hardware, on the compiler and how the system is configured. A sample output is as follows:
42+
43+
```
44+
$ ./bulk-insert-and-query.exe 10000000
45+
find find find find find optimal wasted million
46+
add remove 0% 25% 50% 75% 100% ε bits/item bits/item space keys
47+
48+
add cycles: 325.5/key, instructions: (303.2/key, 0.93/cycle) cache misses: 12.41/key branch misses: 1.17/key
49+
0.00% cycles: 81.7/key, instructions: ( 48.0/key, 0.59/cycle) cache misses: 3.06/key branch misses: 0.00/key
50+
0.25% cycles: 81.8/key, instructions: ( 48.0/key, 0.59/cycle) cache misses: 3.06/key branch misses: 0.00/key
51+
0.50% cycles: 81.8/key, instructions: ( 48.0/key, 0.59/cycle) cache misses: 3.06/key branch misses: 0.00/key
52+
0.75% cycles: 82.0/key, instructions: ( 48.0/key, 0.59/cycle) cache misses: 3.06/key branch misses: 0.00/key
53+
1.00% cycles: 81.9/key, instructions: ( 48.0/key, 0.59/cycle) cache misses: 3.06/key branch misses: 0.00/key
54+
Xor8 106.79 0.00 25.92 25.88 25.86 25.94 25.98 0.3892% 9.84 8.01 22.9% 10.0
55+
56+
... # many more lines omitted
1957
```
2058

59+
The `add` lines preceding the name of each algorithm gives you information regarding the construction time whereas
60+
the other five lines give you information regarding the queries where a given percentage of elements are present
61+
in the set. We use Linux performance counters to measure instructions, cache misses and branch misses.
62+
63+
As part of the benchmark, we check the correctness of the implementation.
64+
65+
## Benchmarking
66+
67+
The shell script `benchmark/benchmark.sh` runs the benchmark 3 times for the most important algorithms,
68+
with entry sizes of 10 million and 100 million keys.
69+
It is much slower than the above, because each invocation runs only one algorithm
70+
(to ensure running one algorithm doesn't influence benchmark results of other algorithms).
71+
It stores the results in the file `benchmark-results.txt`.
72+
To futher analyze the results, use the java tool `AnalyzeResults.java`
73+
from the project https://github.com/FastFilter/fastfilter_java.
74+
Requires GCC and Java 8.
75+
To get a low error, it is best run on a Linux machine that is not otherwise in use.
76+
Steps to run the tests and analyze the results:
77+
78+
git clone https://github.com/FastFilter/fastfilter_cpp.git
79+
git clone https://github.com/FastFilter/fastfilter_java.git
80+
cd fastfilter_cpp/benchmarks
81+
make clean ; make
82+
# this may take an hour to run
83+
./benchmark.sh
84+
85+
cd ../..
86+
cd fastfilter_java
87+
mvn clean install
88+
java -cp target/test-classes org.fastfilter.analysis.AnalyzeResults ../fastfilter_cpp/benchmarks/benchmark-results.txt
89+
2190

2291
## Where is your code?
2392

24-
The filter implementations are in `src`, most are single header files and depend on `src/hashutil.h`:
93+
The filter implementations are in `src/<type>/`. Most implementations depend on `src/hashutil.h`. Examples:
2594

26-
* src/bloom.h
27-
* src/xorfilter.h
95+
* src/bloom/bloom.h
96+
* src/xorfilter/xorfilter.h
2897

2998
## Credit
3099

31100
The cuckoo filter and the benchmark are derived from https://github.com/efficient/cuckoofilter by Bin Fan et al.
101+
The SIMD blocked Bloom filter is from https://github.com/apache/impala (via the cuckoo filter).
102+
The Morton filter is from https://github.com/AMDComputeLibraries/morton_filter.
103+
The Counting Quotient Filter (CQF) is from https://github.com/splatlab/cqf.
104+
105+
106+
# Implementations of xor filters in other programming languages
107+
108+
* [Go](https://github.com/FastFilter/xorfilter)
109+
* [Erlang](https://github.com/mpope9/exor_filter)
110+
* Rust: [1](https://github.com/bnclabs/xorfilter), [2](https://github.com/codri/xorfilter-rs), [3](https://github.com/Polochon-street/rustxorfilter)
111+
* [Java](https://github.com/FastFilter/fastfilter_java)
112+
* [C](https://github.com/FastFilter/xor_singleheader)
113+
* [Python](https://github.com/GreyDireWolf/pyxorfilter)

benchmarks/Makefile

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,28 @@
22
OPT = -O3 -DNDEBUG
33
#OPT = -g -ggdb
44

5-
CXXFLAGS += -fno-strict-aliasing -Wall -std=c++11 -I. -I../src/ $(OPT)
5+
CXXFLAGS += -fno-strict-aliasing -Wall -std=c++11 -I. -I../src/ \
6+
-I../src/bloom/ -I../src/cuckoo/ -I../src/gcs \
7+
-I../src/gqf/ -I../src/morton/ -I../src/xorfilter \
8+
$(OPT)
69

710
UNAME_P := $(shell uname -p)
811
ifeq ($(UNAME_P),aarch64)
9-
CXXFLAGS +=
12+
CXXFLAGS +=
1013
else
1114
ifeq ($(UNAME_P),unknown)
12-
CXXFLAGS +=
15+
CXXFLAGS +=
1316
else
1417
CXXFLAGS += -march=native
1518
endif
1619
endif
1720

18-
LDFLAGS = -Wall
19-
20-
HEADERS = $(wildcard ../src/*.h) *.h
21-
21+
LDFLAGS = -Wall
2222

23+
HEADERS = $(wildcard ../src/*.h \
24+
../src/bloom/*.h ../src/cuckoo/*.h ../src/gcs/*.h \
25+
../src/gqf/*.h ../src/morton/*.h ../src/xorfilter/*.h \
26+
) *.h
2327

2428
.PHONY: all
2529

benchmarks/benchmark-cuckoo315.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/sh
2+
# run the benchmark multiple times with all important algorithms
3+
# for algorithm ids and other parameters, see
4+
# bulk-insert-and-query.cc
5+
#
6+
# rnd: random number generators to use
7+
for rnd in `seq -1 -1`; do
8+
# alg: algorithms to test
9+
for alg in 11 12 13 15 16 17; do
10+
# m: number of entries
11+
for m in 315; do
12+
# test: test id
13+
for test in `seq 1 3`; do
14+
now=$(date +"%T");
15+
echo ${now} alg ${alg} size ${m} ${rnd};
16+
./bulk-insert-and-query.exe ${m}00000 ${alg} ${rnd};
17+
done;
18+
done;
19+
done;
20+
done > benchmark-results.txt 2>&1

benchmarks/benchmark.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/sh
2+
# run the benchmark multiple times with all important algorithms
3+
# for algorithm ids and other parameters, see
4+
# bulk-insert-and-query.cc
5+
#
6+
# rnd: random number generators to use
7+
for rnd in `seq -1 -1`; do
8+
# alg: algorithms to test
9+
for alg in 0 2 3 4 11 12 13 15 16 17 20 30 40 41 42 51 80 100; do
10+
# m: number of entries
11+
for m in `seq 10 90 100`; do
12+
# test: test id
13+
for test in `seq 1 3`; do
14+
now=$(date +"%T");
15+
echo ${now} alg ${alg} size ${m} ${rnd};
16+
./bulk-insert-and-query.exe ${m}000000 ${alg} ${rnd};
17+
done;
18+
done;
19+
done;
20+
done > benchmark-results.txt 2>&1

0 commit comments

Comments
 (0)