multithreading - How to get speed by multiprocessing in Python (linux), insteed of losing -
i search way use cores. try, decrease spreed.
i tried following:
from joblib import parallel, delayed import multiprocessing time import time import numpy np inputs = range(1000) def processinput(i): return *
using multiprocessing
num_cores = multiprocessing.cpu_count() start=time() results = parallel(n_jobs=num_cores)(delayed(processinput)(i) in inputs) print 'multiproc time ', time()-start
without multiprocessing
start=time() results =[] in inputs: results.append(processinput(i)) print 'simple time ', time()-start
and output:
multiproc time 0.14687204361 simple time 0.000839948654175
this classic problem multi-threading / multi-processing. whenever want process in parallel, should make sure time saving because of parallelism greater time takes manage parallel processes.
try increasing input size. see impact of parallelism.
Comments
Post a Comment