About threads in python
Hans Georg Schaathun
hg at schaathun.net
Mon Apr 25 21:31:27 CEST 2011
On Fri, 22 Apr 2011 12:19:56 -0700 (PDT), sturlamolden
<sturlamolden at yahoo.no> wrote:
: To optimise computational code, notice that Python itself
: gives you a 200x performance penalty. That is much more
: important than not using all 4 cores on a quadcore processor.
: In this case, start by identifying bottlenecks using the
: profiler. Then apply C libraries or these or rewrite to Cython.
: If that is not sufficient, you can start to think about using
: more hardware (e.g. multithreading in C or Cython). This advice
: only applies to computational code though.
And not necessarily even there. The extra programmers to recode
in C come with more than a 200x cost factor. It is almost trivial
to make a multithread map implementation which could have exploited
umpteen core box were it not for GIL. That would be a cheap gain.
It matters little that you could gain 100x more at 200x cost ...
Besides, the bottleneck is likely to be deeply embedded in some
library like numpy or scipy already.
:-- Hans Georg
More information about the Python-list