def test_sharing(self): print "Test started\n" bf1 = self.bloomfilter bf2 = peloton_bloomfilters.SharedMemoryBloomFilter( self.fd.name, 50, 0.001) self.assertEquals(len(bf2), 0) self.assertNotIn(1, bf1) self.assertNotIn(1, bf2) bf1.add(1) self.assertIn(1, bf1) self.assertIn(1, bf2) bf2.add(2) self.assertIn(2, bf1) self.assertIn(2, bf2)
def test_capacity_in_sync(self): bf1 = self.bloomfilter bf2 = peloton_bloomfilters.SharedMemoryBloomFilter( self.fd.name, 50, 0.001) bfs = [bf1, bf2] for i in xrange(50): bfs[i % 2].add(i) for i in xrange(50): self.assertIn(i, bf1) self.assertIn(i, bf2) self.assertTrue(bf2.add(50)) for i in xrange(50): self.assertNotIn(i, bf1) self.assertNotIn(i, bf2) self.assertIn(50, bf1) self.assertIn(50, bf2)
import peloton_bloomfilters try: range = xrange except NameError: pass NS = 10**9 for _p in range(1, 3): p = 10**_p for e in range(9): with tempfile.NamedTemporaryFile() as f: X = int(1000 * 10**(e / 2.0)) print(X, p, end='') name = f.name bloomfilter = peloton_bloomfilters.SharedMemoryBloomFilter( name, X + 1, 1.0 / p) t = time.time() for x in range(X): bloomfilter.add(x) print((time.time() - t) / X * NS, end='') t = time.time() for x in range(X): x in bloomfilter print((time.time() - t) / X * NS, end='') t = time.time() for x in range(X, 2 * X): x in bloomfilter print((time.time() - t) / X * NS)
def setUp(self): self.fd = tempfile.NamedTemporaryFile() self.bloomfilter = peloton_bloomfilters.SharedMemoryBloomFilter( self.fd.name, 50, 0.001)