PIL speed and fear

Jeff Shannon jeff at ccvcorp.com
Fri Jun 1 18:02:53 EDT 2001


"akhar" <akhar at videotron.ca> wrote in message news:<s0RR6.13320$sc4.556028 at wagner.videotron.net>...
> What if I thread the gui and the image filters? will that get me a speed
> boost?

As I understand it, (though I'm *far* from being an expert), threading will 
only give speed advantages in a few situations--

1) Each thread spends a fair amount of its time waiting for an external 
resource, such as disk access, serial/network i/o, etc, or

2) Multiple processors are available, and each thread can run on a different
processor.

If you have multiple threads that are all CPU-bound, then you're not going to
be running any faster than with a single thread--possibly slower, due to the
cost of the context switch (and possibly virtual memory paging.... )  The 
advantage of multithreading (at least, on a single CPU) is that, while 
thread A waits for input, thread B can make use of the CPU's free cycles.  

Well, there's also the arguable advantage that multithreading makes code 
more understandable by separating different logical units, but it also 
creates complications with thread-safety and race conditions and such, so 
ease of comprehension could favor either multi- or single-threading, 
depending on your POV .......

In your specific case, I'd presume that the filtering would be CPU bound, and
I'd *guess* that your gui would be as well, so multithreading will probably
not gain you too much, speed-wise, unless you've got multiple processors. 
Of course, my guess may well be wrong, so maybe you should test it
out yourself.  :)

Jeff Shannon
Technician/Programmer
Credit International



More information about the Python-list mailing list