Skip to content
This repository has been archived by the owner on Nov 15, 2024. It is now read-only.

Commit

Permalink
update tests, add timing functions
Browse files Browse the repository at this point in the history
  • Loading branch information
daedalus committed Mar 17, 2023
1 parent b05c8ef commit 2cfd4ab
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
2 changes: 1 addition & 1 deletion fastBloomFilter/bloom.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import bitarray
import binascii
from tqdm import tqdm
from lib.pickling import *
from fastBloomFilter.lib.pickling import *

is_python3 = sys.version_info.major == 3

Expand Down
14 changes: 14 additions & 0 deletions fastBloomFilter/lib/timing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from functools import wraps
from time import time
import sys

def timing(f):
@wraps(f)
def wrap(*args, **kw):
ts = time()
result = f(*args, **kw)
te = time()
sys.stderr.write('func:%r args:[%r, %r] took: %2.4f sec\n' % \
(f.__name__, args, kw, te-ts))
return result
return wrap
36 changes: 36 additions & 0 deletions tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from fastBloomFilter.bloom import *
from fastBloomFilter.lib.timing import *

bf0 = BloomFilter(array_size=128 * (1024 ** 2))
bf0.save("1.b")
bf0.calc_hashid()
bf0.stat()

bf0.add("30000")
bf0.add("1230213")
bf0.add("1")

bf1 = BloomFilter()
bf1.calc_hashid()
bf1.stat()

bf1.load("1.b")
bf1.calc_hashid()
bf1.stat()

assert bf1.update("1") == False
assert bf1.update("2") == False
assert bf1.query("1")

@timing
def test_timing_add(L=10**5):
for i in range(0, L + 1):
bf0.add(str(i))

@timing
def test_timing_query(L=10**5):
for i in range(0, L + 1):
bf0.query(str(i))

test_timing_add()
test_timing_query()

0 comments on commit 2cfd4ab

Please sign in to comment.