Skip to content

Commit

Permalink
Improved speed.
Browse files Browse the repository at this point in the history
  • Loading branch information
Riahiamirreza committed Aug 8, 2022
1 parent ca774ca commit 6b4e977
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
19 changes: 12 additions & 7 deletions bench/stats_of_false_positive.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,40 @@
import secrets

import time

from bf import BloomFilter


def get_false_positive_ratio(
bit_vector_size: int = 2**18,
space: int = 50000,
bit_vector_size: int = 2**25,
space: int = 500000,
does_not_contain_attempts: int = 500
):
f = BloomFilter(bit_vector_size=bit_vector_size)
items = [
secrets.token_bytes(15) for _ in range(space)
]

t1 = time.time()
[
f.insert(item) for item in items
]

t2 = time.time()
print('t2-t1: ', t2 - t1)
false_positive_count: int = 0

t3 = time.time()
for i in (secrets.token_bytes(25) for _ in range(does_not_contain_attempts)):
if f.contain(i):
false_positive_count += 1

t4 = time.time()
print('t4-t3: ', t4 - t3)

return false_positive_count


if '__main__' == __name__:
c = 20
attempts = 500
c = 1
attempts = 50000
total = 0
for _ in range(c):
total += get_false_positive_ratio(does_not_contain_attempts=attempts)
Expand Down
1 change: 0 additions & 1 deletion bf/bit_vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

class BitVector:
def __init__(self, size: int):
# self.vector = array('B', [0] * size)
self.vector = bytearray((0,) * size)

def set_to_one(self, *indices: int):
Expand Down

0 comments on commit 6b4e977

Please sign in to comment.