Skip to content

Instantly share code, notes, and snippets.

@icook
Last active March 18, 2017 00:20
Show Gist options
  • Save icook/bf34a38bea98cc02bf72 to your computer and use it in GitHub Desktop.
Save icook/bf34a38bea98cc02bf72 to your computer and use it in GitHub Desktop.
A benchmark for using a Python multiprocessing pool to process pool share submissions
from multiprocessing import Pool
from vtc_scrypt import getPoWHash
from time import sleep
import gevent
import os
import time
def f(x):
return getPoWHash(x)
def f_hndle(pipe):
while True:
pipe.recv()
header_hex = ("01000000" +
"81cd02ab7e569e8bcd9317e2fe99f2de44d49ab2b8851ba4a308000000000000" +
"e320b6c2fffc8d750423db8b1eb942ae710e951ed797f7affc8892b0f1fc122b" +
"c7f5d74d" +
"f2b9441a" +
"42a14695")
header_bin = header_hex.decode('hex')
#durs = []
#for i in xrange(1000):
# start = time.time()
# #result = pool.apply(f, [b])
# result = getPoWHash(header_bin)
# dur = time.time() - start
# durs.append(dur)
#
#print "average time {} us".format(sum(durs) / len(durs) * 1000000)
#exit(0)
procs = []
pipes = []
for i in xrange(4):
pipe = multiprocessing.Pipe()
proc = multiprocessing.Process(
durs = []
def run_proc():
for i in xrange(5):
start = time.time()
result = pool.apply(f, [header_bin])
#result = getPoWHash(header_bin)
dur = time.time() - start
durs.append(dur)
sleep(0.01)
#print "done"
start = time.time()
green = []
for i in xrange(1000):
green.append(gevent.spawn(run_proc))
gevent.joinall(green)
print "runtime {}".format(time.time() - start)
print "average time {} us".format(sum(durs) / len(durs) * 1000000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment