def pyblume_test_fpp(N): print ' a. Creating filter' bloom = pyblume.Filter(1024 * 1024 * 10, 0.000001, "/tmp/pyblume_fpp_test.bf") print ' b. Loading filter' start = time.time() for k in xrange(0, N, 10): bloom.add(str(k)) end = time.time() print ' bloom.add: %d/s' % ((N / 10) / (end - start)) print ' c. Computing false positive rate' fn_count = 0 fp_count = 0 start = time.time() for k in xrange(0, N): hit = str(k) in bloom if hit and k % 10 != 0: fp_count += 1 elif not hit and k % 10 == 0: fn_count += 1 end = time.time() print ' bloom.check: %d/s' % (N / (end - start)) print ' d. %d false positives out of %d trials (p = %0.4f)' % (fp_count, N, float(fp_count) / N)
def pyblume_test_full(N): print ' a. Creating filter' bloom = pyblume.Filter(1024 * 512, 0.000001, "/tmp/pyblume_full_test.bf") print ' b. Loading filter' start = time.time() for k in xrange(0, N, 10): bloom.add(str(k)) end = time.time() print ' bloom.add: %d/s' % ((N / 10) / (end - start))
def create_filter(): print ' a. Creating filter at "%s"' % (filepath,) bloom = pyblume.Filter(1024 * 1024 * 10, 0.000001, filepath) print ' b. Loading filter' start = time.time() for k in xrange(0, N, 10): bloom.add(str(k)) end = time.time() print ' bloom.add: %d/s' % ((N / 10) / (end - start)) bloom.close()
def pyblume_test_locking(N): print ' a. Creating filter' bloom = pyblume.Filter(1024 * 512, 0.000001, "/tmp/pyblume_locking_test.bf") bloom2 = pyblume.open("/tmp/pyblume_locking_test.bf", for_write=1) print ' b. Loading filter' start = time.time() for k in xrange(0, N, 10): bloom.add(str(k)) end = time.time() print ' bloom.add: %d/s' % ((N / 10) / (end - start))
__author__ = 'rakesh' import pyblume BLOOM_FILTER_MAX_FILESIZE = 1024 * 1024 * 500 BLOOM_ERROR_RATE = 0.000001 fileloc = "/tmp/test.blume" bf = pyblume.Filter(BLOOM_FILTER_MAX_FILESIZE, BLOOM_ERROR_RATE, fileloc) for i in range(313): bf.add(str(i)) bf.close() check = [str(j) for j in range(300, 400)] print check bf = pyblume.open(fileloc, for_write=False) for x in check: if x in bf: print "Found" bf.close() ''' NOTES: Bloom Filters Description - https://www.pinterest.com/pin/429953095654194981/