# Collection of code snippets by Arne Vajhøj 
# (from articles on eksperten.dk / vajhoej.dk written sometime between 2004 and now) 
import redis
import time

PERFORMANCE_CACHE = 1
cache = redis.Redis(host='localhost',port=6379,db=PERFORMANCE_CACHE)

# put speed
N = 10000
for j in range(5):
    t1 = time.time()
    for i in range(N):
        cache.set("K#" + str(i + 1), i + 1);
    t2 = time.time()
    print("%d puts per second" % (N / (t2 - t1)))

cache.close()
