-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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