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

Commit

Permalink
Add python3 support
Browse files Browse the repository at this point in the history
  • Loading branch information
Bachmann1234 committed Jun 11, 2014
1 parent 700c1e7 commit 70e25c6
Show file tree
Hide file tree
Showing 9 changed files with 105 additions and 347 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ language: python
python:
- "2.6"
- "2.7"
- "3.4"

install:
- pip install -r requirements.txt
Expand Down
270 changes: 0 additions & 270 deletions ez_setup.py

This file was deleted.

1 change: 0 additions & 1 deletion pybloom/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
"""pybloom
"""
from pybloom import BloomFilter, ScalableBloomFilter, __version__, __author__
32 changes: 17 additions & 15 deletions pybloom/benchmarks.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,44 +4,46 @@
import sys
from pybloom import BloomFilter
import bitarray, math, time
from utils import range_fn


def main(capacity=100000, request_error_rate=0.1):
f = BloomFilter(capacity=capacity, error_rate=request_error_rate)
assert (capacity == f.capacity)
start = time.time()
for i in xrange(0, f.capacity):
for i in range_fn(0, f.capacity):
f.add(i, skip_check=True)
end = time.time()
print "{:5.3f} seconds to add to capacity, {:10.2f} entries/second".format(
end - start, f.capacity / (end - start))
print("{:5.3f} seconds to add to capacity, {:10.2f} entries/second".format(
end - start, f.capacity / (end - start)))
oneBits = f.bitarray.count(True)
zeroBits = f.bitarray.count(False)
#print "Number of 1 bits:", oneBits
#print "Number of 0 bits:", zeroBits
print "Number of Filter Bits:", f.num_bits
print "Number of slices:", f.num_slices
print "Bits per slice:", f.bits_per_slice
print "------"
print "Fraction of 1 bits at capacity: {:5.3f}".format(
oneBits / float(f.num_bits))
print("Number of Filter Bits:", f.num_bits)
print("Number of slices:", f.num_slices)
print("Bits per slice:", f.bits_per_slice)
print("------")
print("Fraction of 1 bits at capacity: {:5.3f}".format(
oneBits / float(f.num_bits)))
# Look for false positives and measure the actual fp rate
trials = f.capacity
fp = 0
start = time.time()
for i in xrange(f.capacity, f.capacity + trials + 1):
for i in range_fn(f.capacity, f.capacity + trials + 1):
if i in f:
fp += 1
end = time.time()
print ("{:5.3f} seconds to check false positives, "
"{:10.2f} checks/second".format(end - start, trials / (end - start)))
print "Requested FP rate: {:2.4f}".format(request_error_rate)
print "Experimental false positive rate: {:2.4f}".format(fp / float(trials))
print(("{:5.3f} seconds to check false positives, "
"{:10.2f} checks/second".format(end - start, trials / (end - start))))
print("Requested FP rate: {:2.4f}".format(request_error_rate))
print("Experimental false positive rate: {:2.4f}".format(fp / float(trials)))
# Compute theoretical fp max (Goel/Gupta)
k = f.num_slices
m = f.num_bits
n = f.capacity
fp_theory = math.pow((1 - math.exp(-k * (n + 0.5) / (m - 1))), k)
print "Projected FP rate (Goel/Gupta): {:2.6f}".format(fp_theory)
print("Projected FP rate (Goel/Gupta): {:2.6f}".format(fp_theory))

if __name__ == '__main__' :
status = main()
Expand Down
Loading

0 comments on commit 70e25c6

Please sign in to comment.