Skip to content

Instantly share code, notes, and snippets.

@paulwinex
Created September 5, 2016 05:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paulwinex/abc51a3a447dc18d78675fad2747ff09 to your computer and use it in GitHub Desktop.
Save paulwinex/abc51a3a447dc18d78675fad2747ff09 to your computer and use it in GitHub Desktop.
import redis, time
rds = redis.Redis("localhost", 6379)
rds.flushdb()
# fill 1
users = {"user%s" % x: "channel%s" % x for x in range(500)}
rds.hmset("users1", users)
# fill 2
for i in range(100):
rds.sadd('users2', 'user%s|channel%s' % (i, i))
# tests
getuser = 'user450'
count = 10000
# get 1
st = time.time()
for i in range(count):
chann = rds.hgetall("users1").get(getuser)
print 'Redis dict:', time.time() - st
# get 2
def get_split(name):
for u in rds.smembers("users2"):
u, c = u.split('|')
if u == name:
return c
st = time.time()
for i in range(count):
chann = get_split(getuser)
print 'Iter and split:', time.time() - st
'''
Redis dict: 28.6445989609
Iter and split: 3.94548511505
'''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment