Created
May 7, 2010 22:18
-
-
Save andymccurdy/394068 to your computer and use it in GitHub Desktop.
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 time | |
import threading | |
import redis | |
def worker(): | |
print "starting thread..." | |
r = redis.Redis(db=9) | |
for i in xrange(2000): | |
r.incr('foo') | |
def worker_with_pipeline(): | |
print "starting thread..." | |
r = redis.Redis(db=9) | |
p = r.pipeline() | |
for i in xrange(2000): | |
p.incr('foo') | |
p.execute() | |
def test(pipeline): | |
target = pipeline and worker_with_pipeline or worker | |
threads = [] | |
for i in range(50): | |
threads.append(threading.Thread(target=target)) | |
start = time.time() | |
for t in threads: | |
t.start() | |
for t in threads: | |
t.join() | |
end = time.time()-start | |
print end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment