Skip to content

Instantly share code, notes, and snippets.

@etataurov
Created July 21, 2014 06:13
Show Gist options
  • Save etataurov/88b0efb495584bead0c6 to your computer and use it in GitHub Desktop.
Save etataurov/88b0efb495584bead0c6 to your computer and use it in GitHub Desktop.
txredisapi little benchmark
import time
from twisted.internet import defer
from twisted.internet import reactor
import txredisapi as redis
HOST = 'localhost'
PORT = 6379
N = 1000
@defer.inlineCallbacks
def test_setget():
key = 'test'
conn = yield redis.Connection(HOST, PORT)
start = time.time()
for i in xrange(N):
yield conn.set(key, 'test_data')
yield conn.get(key)
print "done set-get: %.4fs." % ((time.time() - start) / N)
@defer.inlineCallbacks
def test_lrange():
key = 'test_list'
conn = yield redis.Connection(HOST, PORT)
for i in xrange(N):
yield conn.lpush(key, str(i))
start = time.time()
for i in xrange(N):
yield conn.lrange(key, 0, 999)
print "done lrange: %.4fs." % ((time.time() - start) / N)
@defer.inlineCallbacks
def run():
yield test_setget()
yield test_lrange()
reactor.stop()
run()
reactor.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment