To thread or not to thread
grante at visi.com
Thu Jul 28 22:53:30 CEST 2005
On 2005-07-28, Sidd <iamsidd at gmail.com> wrote:
> I was recently reading an article on threading in python and I
> came across Global Interpreter Lock,now as a novince in python
> I was cusrious about
> 1.Is writing a threaded code in python going to perform well
> than a normal python code.
It's sort of a corrolary to Amdahls law: on a single CPU
machine, optimally written multi-threaded code will always
perform worse than optimally written single-threaded code.
[Where performance is in terms of CPU efficiency.]
However, it may be very difficult to write optimal
single-threaded code, and much easier to write (nearly) optimal
multi-threaded code. So, in practice, multi-threaded code
often performs better for certain classes of problems.
> If so on what basis can it performance be measured.
That's up to whoever is doing the measuring.
> 2.Is writing a threaded code in python better than a code
> written in C/C++ using PTHREADS.
On a multi-CPU machine you can get much more parallelism for
compute-intensive tasks using C/pthreads than you can using
It's also a lot easier to write buggy code containing race
conditions using C/pthreads.
Grant Edwards grante Yow! I want to read my new
at poem about pork brains and
visi.com outer space...
More information about the Python-list