Last active
October 29, 2024 17:56
-
-
Save rt121212121/d8991a89497cc7a1962bd28fd437d1a4 to your computer and use it in GitHub Desktop.
Cuckoo filter testing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import defaultdict | |
import os | |
import bsvcuckoo | |
LOOKUP_COUNT = 1000000 | |
ITERATIONS = 100 | |
MAX_KICK_COUNT = 1 | |
with open("test.csv", "w") as f: | |
print("maximum entries, added entries, minimum, maximum, average", file=f) | |
maximum_entries = 16000 | |
while maximum_entries <= 512000: | |
false_positive_map: dict[int, list[int]] = defaultdict(list) | |
for i in range(ITERATIONS): | |
print(f"{i}, ", end="", flush=True) | |
filter = bsvcuckoo.CuckooFilter(maximum_entries, MAX_KICK_COUNT, 1644963952) | |
addition_count = 2000 | |
last_addition_count = 0 | |
while addition_count <= maximum_entries: | |
for i in range(last_addition_count, addition_count): | |
k = os.urandom(32) | |
filter.add(k) | |
false_positives = 0 | |
for j in range(LOOKUP_COUNT): | |
k = os.urandom(32) | |
if filter.contains(k) == 0: | |
false_positives += 1 | |
false_positive_map[addition_count].append(false_positives) | |
last_addition_count = addition_count | |
addition_count *= 2 | |
print() | |
for addition_count, false_positive_counts in false_positive_map.items(): | |
print(f"{maximum_entries:15}, {addition_count:13}, {min(false_positive_counts):7}, " | |
f"{max(false_positive_counts):7}, {sum(false_positive_counts)/ITERATIONS:7.1f}", | |
file=f) | |
maximum_entries *= 2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment