Skip to content

Instantly share code, notes, and snippets.

@nailor
Created September 13, 2013 15:48
Show Gist options
  • Save nailor/6552432 to your computer and use it in GitHub Desktop.
Save nailor/6552432 to your computer and use it in GitHub Desktop.
Dead simple benchmark for testing sparkey. Running: $ python <amount-of-entries> <amount-of-random-reads> (or use pypy, speed guaranteed)
from __future__ import print_function
import os
import sys
import sparkey
import tempfile
import timeit
from random import randint
def main(hashfile, logfile, size, lookups):
writer = sparkey.HashWriter(hashfile, logfile)
for i in xrange(size):
writer.put('key_%d' % i, 'value_%d' % i)
writer.close()
reader = sparkey.HashReader(hashfile, logfile)
for _ in xrange(lookups):
reader['key_%d' % randint(0, size - 1)]
reader.close()
if __name__ == '__main__':
def _timed(size, lookups):
try:
_, hash = tempfile.mkstemp(dir='.')
_, log = tempfile.mkstemp(dir='.')
print('writing', hash, log)
main(hash, log, size, lookups)
finally:
os.remove(hash)
os.remove(log)
print(timeit.repeat('_timed(%s)' % ','.join(sys.argv[1:]),
setup='from __main__ import _timed',
number=10, repeat=3))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment