Skip to content

Instantly share code, notes, and snippets.

@icook
Created July 13, 2014 21:56
Show Gist options
  • Save icook/4e0395558fc3e38867b2 to your computer and use it in GitHub Desktop.
Save icook/4e0395558fc3e38867b2 to your computer and use it in GitHub Desktop.
A simple benchmark of how long the redis keys command takes to run at various keyspace sizes.
import random
import redis
r = redis.StrictRedis(host='localhost', port=6379, db=15)
r.flushdb()
def rand_str(N):
return ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(N))
for i in xrange(1000000):
r.set(rand_str(10), "testing")
if i % 10000 == 0:
t = time.time()
res = r.keys("ab*")
print "keys {}; matches {}; time {}".format(i, len(res), time.time() - t)
"""
Output on 16GB, i5 3570k, Raid 0 SSD
keys 0; matches 0; time 0.000168800354004
keys 10000; matches 0; time 0.000463962554932
keys 20000; matches 0; time 0.00136685371399
keys 30000; matches 0; time 0.00133585929871
keys 40000; matches 0; time 0.00214290618896
keys 50000; matches 0; time 0.00226593017578
keys 60000; matches 0; time 0.00410294532776
keys 70000; matches 0; time 0.00347685813904
keys 80000; matches 0; time 0.00406694412231
keys 90000; matches 0; time 0.00511598587036
keys 100000; matches 0; time 0.00605797767639
keys 110000; matches 0; time 0.00584506988525
keys 120000; matches 0; time 0.006432056427
keys 130000; matches 0; time 0.00774693489075
keys 140000; matches 0; time 0.00930786132812
keys 150000; matches 0; time 0.00945711135864
keys 160000; matches 0; time 0.00815105438232
keys 170000; matches 0; time 0.0136659145355
keys 180000; matches 0; time 0.0108909606934
keys 190000; matches 0; time 0.0138669013977
keys 200000; matches 0; time 0.0119860172272
keys 210000; matches 0; time 0.0163519382477
keys 220000; matches 0; time 0.0154550075531
keys 230000; matches 0; time 0.0136239528656
keys 240000; matches 0; time 0.0158610343933
keys 250000; matches 0; time 0.0134558677673
keys 260000; matches 0; time 0.0154469013214
keys 270000; matches 0; time 0.0177111625671
keys 280000; matches 0; time 0.0211009979248
keys 290000; matches 0; time 0.0180811882019
keys 300000; matches 0; time 0.0222141742706
keys 310000; matches 0; time 0.0200428962708
keys 320000; matches 0; time 0.0204169750214
keys 330000; matches 0; time 0.0216569900513
keys 340000; matches 0; time 0.021614074707
keys 350000; matches 0; time 0.025139093399
keys 360000; matches 0; time 0.0218448638916
keys 370000; matches 0; time 0.025573015213
keys 380000; matches 0; time 0.0252211093903
keys 390000; matches 0; time 0.023530960083
keys 400000; matches 0; time 0.0240268707275
keys 410000; matches 0; time 0.0283708572388
keys 420000; matches 0; time 0.0281610488892
keys 430000; matches 0; time 0.0289740562439
keys 440000; matches 0; time 0.0314679145813
keys 450000; matches 0; time 0.0287611484528
keys 460000; matches 0; time 0.0279700756073
keys 470000; matches 0; time 0.0326099395752
keys 480000; matches 0; time 0.0290122032166
keys 490000; matches 0; time 0.0347850322723
keys 500000; matches 0; time 0.0376040935516
keys 510000; matches 0; time 0.0320620536804
keys 520000; matches 0; time 0.0374939441681
keys 530000; matches 0; time 0.0416660308838
keys 540000; matches 0; time 0.0427198410034
keys 550000; matches 0; time 0.0426428318024
keys 560000; matches 0; time 0.0411550998688
keys 570000; matches 0; time 0.0375699996948
keys 580000; matches 0; time 0.041543006897
keys 590000; matches 0; time 0.0416131019592
keys 600000; matches 0; time 0.0391709804535
keys 610000; matches 0; time 0.0421750545502
keys 620000; matches 0; time 0.0421669483185
keys 630000; matches 0; time 0.0435750484467
keys 640000; matches 0; time 0.0428659915924
keys 650000; matches 0; time 0.0432200431824
keys 660000; matches 0; time 0.0433650016785
keys 670000; matches 0; time 0.04576420784
keys 680000; matches 0; time 0.0440571308136
keys 690000; matches 0; time 0.0485889911652
keys 700000; matches 0; time 0.0514831542969
keys 710000; matches 0; time 0.0492060184479
keys 720000; matches 0; time 0.04709815979
keys 730000; matches 0; time 0.0496110916138
keys 740000; matches 0; time 0.0483069419861
keys 750000; matches 0; time 0.0506930351257
keys 760000; matches 0; time 0.0496380329132
keys 770000; matches 0; time 0.0509629249573
keys 780000; matches 0; time 0.0504992008209
keys 790000; matches 0; time 0.0536229610443
keys 800000; matches 0; time 0.051696062088
keys 810000; matches 0; time 0.055557012558
keys 820000; matches 0; time 0.0539238452911
keys 830000; matches 0; time 0.0556230545044
keys 840000; matches 0; time 0.0548131465912
keys 850000; matches 0; time 0.0594198703766
keys 860000; matches 0; time 0.0576419830322
keys 870000; matches 0; time 0.0581479072571
keys 880000; matches 0; time 0.0599980354309
keys 890000; matches 0; time 0.0605928897858
keys 900000; matches 0; time 0.0590078830719
keys 910000; matches 0; time 0.0621252059937
keys 920000; matches 0; time 0.0587120056152
keys 930000; matches 0; time 0.0624170303345
keys 940000; matches 0; time 0.0678188800812
keys 950000; matches 0; time 0.0658578872681
keys 960000; matches 0; time 0.0650570392609
keys 970000; matches 0; time 0.0644581317902
keys 980000; matches 0; time 0.0735559463501
keys 990000; matches 0; time 0.0649890899658
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment