Skip to content

Instantly share code, notes, and snippets.

@aluzzardi
Created October 22, 2012 08:07
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 aluzzardi/9557d14ae83b939f1fd6 to your computer and use it in GitHub Desktop.
Save aluzzardi/9557d14ae83b939f1fd6 to your computer and use it in GitHub Desktop.
Quick and dirty test to see how tries compare to hash tables in this specific case
from redis import Redis
import time
r = Redis()
keys = []
for a in xrange(ord('a'), ord('z')):
for b in xrange(ord('a'), ord('z')):
for c in xrange(ord('a'), ord('z')):
keys.append('{0}{1}{2}'.format(a, b, c))
keyvals = []
for k in keys:
keyvals.append(k)
keyvals.append('xxx')
r.execute_command('hmset', 'hash', *keyvals)
r.execute_command('tmset', 'trie', *keyvals)
start = time.time()
[r.execute_command('hmget','hash', *keys) for i in range(0, 1000)]
end = time.time()
print '1000 HGET performed in {0} seconds'.format(end - start)
start = time.time()
[r.execute_command('tmget', 'trie', *keys) for i in range(0, 1000)]
end = time.time()
print '1000 TGET performed in {0} seconds'.format(end - start)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment