Created
November 24, 2012 15:33
-
-
Save mocobeta/4140156 to your computer and use it in GitHub Desktop.
KVS性能比較/測定
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
## memcached, Couchbaseで使用 | |
import sys | |
import pylibmc | |
import md5 | |
import time | |
import random | |
host = 'host:port' | |
mc = pylibmc.Client([host]) | |
ITEM_COUNT = 1000000 | |
SET_TIMES = [] | |
for c in range(0, 10): | |
t1 = time.time() * 1000 | |
for i in range(0, 1000): | |
key = md5.new(str(random.randint(1, ITEM_COUNT-1))).hexdigest() | |
val = key * 4 | |
mc.set(key, val) | |
t2 = time.time() * 1000 | |
SET_TIMES.append(t2 - t1) | |
avg = sum(SET_TIMES) / 10 | |
print 'SET TIME(1000 items): %f ms' % (avg) | |
GET_TIMES = [] | |
for c in range(0, 10): | |
t1 = time.time() * 1000 | |
for i in range(0, 1000): | |
key = md5.new(str(random.randint(1, ITEM_COUNT-1))).hexdigest() | |
mc.get(key) | |
t2 = time.time() * 1000 | |
GET_TIMES.append(t2 - t1) | |
avg = sum(GET_TIMES) / 10 | |
print 'GET TIME(1000 items): %f ms' % (avg) |
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
import sys | |
import pymongo | |
import md5 | |
import time | |
import random | |
host = 'host:port' | |
conn = pymongo.Connection([host]) | |
db = conn.test | |
ITEM_COUNT = 1000000 | |
SET_TIMES = [] | |
for c in range(0, 10): | |
t1 = time.time() * 1000 | |
for i in range(0, 1000): | |
key = md5.new(str(random.randint(1, ITEM_COUNT-1))).hexdigest() | |
val = key * 4 | |
db.mycoll.save({'_id': key, 'val': val}, safe=True) | |
t2 = time.time() * 1000 | |
SET_TIMES.append(t2 - t1) | |
print str(SET_TIMES) | |
avg = sum(SET_TIMES) / 10 | |
print 'SET TIME(1000 items): %f ms' % (avg) | |
GET_TIMES = [] | |
for c in range(0, 10): | |
t1 = time.time() * 1000 | |
for i in range(0, 1000): | |
key = md5.new(str(random.randint(1, ITEM_COUNT-1))).hexdigest() | |
db.mycoll.find_one(key) | |
t2 = time.time() * 1000 | |
GET_TIMES.append(t2 - t1) | |
avg = sum(GET_TIMES) / 10 | |
print 'GET TIME(1000 items): %f ms' % (avg) |
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
import redis | |
import md5 | |
import time | |
import random | |
host = 'host' | |
port = port | |
rc = redis.Redis(host, port) | |
ITEM_COUNT = 1000000 | |
SET_TIMES = [] | |
for c in range(0, 10): | |
t1 = time.time() * 1000 | |
for i in range(0, 1000): | |
key = md5.new(str(random.randint(1, ITEM_COUNT-1))).hexdigest() | |
val = key * 4 | |
rc.set(key, val) | |
t2 = time.time() * 1000 | |
SET_TIMES.append(t2 - t1) | |
avg = sum(SET_TIMES) / 10 | |
print 'SET TIME(1000 items): %f ms' % (avg) | |
GET_TIMES = [] | |
for c in range(0, 10): | |
t1 = time.time() * 1000 | |
for i in range(0, 1000): | |
key = md5.new(str(random.randint(1, ITEM_COUNT-1))).hexdigest() | |
rc.get(key) | |
t2 = time.time() * 1000 | |
GET_TIMES.append(t2 - t1) | |
avg = sum(GET_TIMES) / 10 | |
print 'GET TIME(1000 items): %f ms' % (avg) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment