Skip to content

Instantly share code, notes, and snippets.

@oleiade
Created November 10, 2012 13:47
Show Gist options
  • Save oleiade/4051118 to your computer and use it in GitHub Desktop.
Save oleiade/4051118 to your computer and use it in GitHub Desktop.
python leveldb benchmarks using Hurdl;es
import tempfile
import hurdles
import leveldb
import shutil
from hurdles.tools import extra_setup
common_setup = "import random\n"
class BenchLevelDB(hurdles.BenchCase):
def setUp(self):
self.db_path = '/tmp/testdb'
self.db = leveldb.DB(self.db_path)
self.bootstrap_db()
def tearDown(self):
del self.db
shutil.rmtree(self.db_path)
def bootstrap_db(self):
batch = self.db.batch()
for x in xrange(100000):
batch.put(str(x), str(x))
batch.Write()
@extra_setup(common_setup + "rand_keys = [str(random.randint(1, 99999)) for x in [0] * 10000]\n")
def bench_atomic_get(self, *args, **kwargs):
map(self.db.get, kwargs['rand_keys'])
@extra_setup(common_setup + "rand_keys = [str(random.randint(1, 99999)) for x in [0] * 10000]\n")
def bench_atomic_put(self, *args, **kwargs):
map(lambda kv: self.db.put(kv[0], kv[1]),
zip(kwargs['rand_keys'], kwargs['rand_keys']))
def bench_range(self, *args, **kwargs):
[(k, v) for k, v in self.db.iterator('1')]
def bench_batch_only_put(self, *args, **kwargs):
batch = self.db.batch()
for x in xrange(100000):
batch.put(str(x), str(x))
batch.Write()
def bench_batch_mixed_put_delete(self, *args, **kwargs):
batch = self.db.batch()
for x in xrange(100000):
if x % 3 == 0:
batch.delete(str(x))
else:
batch.put(str(x), str(x))
batch.Write()
@wbolster
Copy link

My leveldb-cython bindings have a .write(), not .Write() on write batches. Are you sure this is the version you used?

@wbolster
Copy link

I've forked this gist to https://gist.github.com/4052036 and added two branches: bm-py-leveldb and a bm-leveldb-cython. The code is the same except for the subtle API differences between py-leveldb and leveldb-cython

@wbolster
Copy link

Fwiw: the github web interface doesn't show branches for gists, it seems, so you may have to clone and "git branch" locally to have a look.

@wbolster
Copy link

Let's move the discussion to https://gist.github.com/4052036

I'll copy my previous comments there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment