multithreading - Evaluating the performance gain from multi-threading in python -


i tried compare performance gain parallel computing using multithreading module , normal sequence computing couldn't find real difference. here's did:

import time, threading, queue q=queue.queue()  def calc(_range):     exponent=(x**5 x in _range)     q.put([x**0.5 x in exponent])  def calc1(_range):     exponent=(x**5 x in _range)     return [x**0.5 x in exponent]  def multithreds(threadlist):     d=[]     x in threadlist:         t=threading.thread(target=calc, args=([x]))         t.start()         t.join()         s=q.get()         d.append(s)     return d   threads=[range(100000), range(200000)]  start=time.time() #out=multithreads(threads) out1=[calc1(x)for x in threads] end=time.time() print end-start 

timing using threading:0.9390001297 timing running in sequence:0.911999940872

the timing running in sequence lower using multithreading. have feeling there's wrong multithreading code.

can point me in right direction please. thanks.

the reference implementation of python (cpython) has so-called interpreter lock 1 thread executes python byte-code. can switch example ironpython has no gil or can take @ multiprocessing module spawns several python processes can execute code independently. in scenarios using threads in python can slower single-thread because context-switches between threads on cpu introduce overhead.

take at page deeper insights , help.

if want dive more deeper in topic can highly recommend this talk david beazley.


Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

Cross-Compiling Linux Kernel for Raspberry Pi - ${CCPREFIX}gcc -v does not work -

java.lang.NoClassDefFoundError When Creating New Android Project -