skeletonz - The simple Python CMS system
import time

import lightcloud
import memcache

mc = memcache.Client(['127.0.0.1:11211'])

def bench_it(op, name, operation, times=10000):
    start = time.time()
    for i in range(0, times):
        operation()
    print 'Elapsed for %s %s: %s seconds [%s]' %\
            (times, op, time.time() - start, name)

#--- Gets ----------------------------------------------
bench_it('gets', 'memcache', lambda: mc.get('hello'))
def lc_get(): lightcloud.get('hello'); lightcloud.clean_local_cache()
bench_it('gets', 'lightcloud', lc_get)

print

#--- Sets ----------------------------------------------
bench_it('sets', 'memcache', lambda: mc.set('hello', 'world'))
bench_it('sets', 'lightcloud', lambda: lightcloud.set('hello', 'world'))

lightcloud.close_open_connections()
Powered by Skeletonz