Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include pydablooms in the speed comparison #25

Open
peterjc opened this issue Sep 13, 2012 · 0 comments
Open

Include pydablooms in the speed comparison #25

peterjc opened this issue Sep 13, 2012 · 0 comments

Comments

@peterjc
Copy link

peterjc commented Sep 13, 2012

Suggested patch to also profile the bitly Dablooms Python wrapper available from https://github.com/bitly/dablooms

diff --git a/tests/comparisons/speedtest.py b/tests/comparisons/speedtest.py
index 8d10a4c..428ebd1 100755
--- a/tests/comparisons/speedtest.py
+++ b/tests/comparisons/speedtest.py
@@ -9,7 +9,7 @@ import pybloomfilter
 
 tempfiles = []
 
-ERROR_RATE = 0.1
+ERROR_RATE = 0.1 #i.e. 10%
 
 #def get_and_add_words(Creator, wordlist):
 def get_and_add_words(Creator, wordlist):
@@ -46,6 +46,7 @@ def create_word_list(filename):
     return words_set
 
 def create_cbloomfilter(*args):
+    """Using pybloomfilter.BloomFilter(capacity, error_rate, temp_file)"""
     args = list(args)
     f = tempfile.NamedTemporaryFile()
     tempfiles.append(f)
@@ -53,6 +54,15 @@ def create_cbloomfilter(*args):
     args.append(f.name)
     return pybloomfilter.BloomFilter(*tuple(args))
 
+def create_dablooms(*args):
+    """Using pydablooms.Dablooms(capacity, error_rate, temp_file)"""
+    args = list(args)
+    f = tempfile.NamedTemporaryFile()
+    tempfiles.append(f)
+    os.unlink(f.name)
+    args.append(f.name)
+    return pydablooms.Dablooms(*tuple(args))
+
 creators = [create_cbloomfilter]
 try:
     import pybloom
@@ -61,27 +71,36 @@ except ImportError:
 else:
     creators.append(pybloom.BloomFilter)
 
+try:
+    import pydablooms
+except ImportError:
+    pass
+else:
+    creators.append(create_dablooms)
+
 def run_test():
     dict_wordlist = create_word_list('words')
     test_wordlist = create_word_list('testwords')
     NUM = 10
 
+    print "Requested error rate %0.1f%%" % (100 * ERROR_RATE)
     for creator in creators:
         start = time.time()
         if NUM:
             t = timeit.Timer(lambda : get_and_add_words(creator, dict_wordlist))
-            print "%s took %0.5f s/run" % (
+            print "%s took %0.5f s/run (get and add words)" % (
                 creator,
                 t.timeit(NUM) / float(NUM))
         bf = get_and_add_words(creator, dict_wordlist)
 
         if NUM:
             t = timeit.Timer(lambda : check_words(bf, test_wordlist))
-            print "%s took %0.5f s/run" % (
+            print "%s took %0.5f s/run (check words)" % (
                 creator,
                 t.timeit(NUM) / float(NUM))
 
-        raw_input()
+        #print "Press enter to continue..."
+        #raw_input()
 
         test_errors(bf, dict_wordlist, test_wordlist)
 

Note this assumes dablooms has added support for 'in' in their Python wrapper - see bitly/dablooms#50 - you could test without it but it would require special case code to use their check method instead.

I'm not sure how representative your test set is but pydablooms is significantly faster (which I also observed on the real data sample I was trying this on). Note on my machine both libraries are doing far better than the requested 10% error rate, although pybloomfiltermmap has the lower error rate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant