Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Fetching contributors…
Cannot retrieve contributors at this time
executable file 80 lines (62 sloc) 2.25 KB
#! /usr/bin/env python
import time
import random
import simhash
import argparse
# Generate some random hashes with known
parser = argparse.ArgumentParser(description='Run a quick bench')
parser.add_argument('--random', dest='random', type=int, default=None,
help='Generate N random hashes for querying')
parser.add_argument('--blocks', dest='blocks', type=int, default=6,
help='Number of blocks to divide 64-bit hashes into')
parser.add_argument('--bits', dest='bits', type=int, default=3,
help='How many bits may differ')
parser.add_argument('--hashes', dest='hashes', type=str, default=None,
help='Path to file with hashes to insert')
parser.add_argument('--queries', dest='queries', type=str, default=None,
help='Path to file with queries to run')
args = parser.parse_args()
corpus = simhash.Corpus(args.blocks, args.bits)
# Hashes to run, query
hashes = []
queries = []
if args.hashes:
with open(args.hashes) as f:
hashes = [int(l) for l in f.split('\n')]
if args.queries:
with open(args.queries) as f:
queries = [int(l) for l in f.split('\n')]
if args.random:
if args.hashes and args.queries:
print 'Random supplied with both --hashes and --queries'
if not hashes:
print 'Generating %i hashes' % args.random
hashes = [random.randint(0, 1 << 64) for i in range(args.random)]
if not queries:
print 'Generating %i queries' % args.random
queries = [random.randint(0, 1 << 64) for i in range(args.random)]
elif not args.hashes or args.queries:
print 'No hashes or queries supplied'
class Timer(object):
def __init__(self, name): = name
def __enter__(self):
self.start = -time.time()
print 'Starting %s' %
return self
def __exit__(self, t, v, tb):
self.start += time.time()
if t:
print ' Failed %s in %fs' % (, self.start)
print ' Ran %s in %fs' % (, self.start)
with Timer('Bulk Insertion'):
with Timer('Bulk Find First'):
with Timer('Bulk Find All'):
with Timer('Bulk Removal'):
Jump to Line
Something went wrong with that request. Please try again.