[python-win32] Efficiency question
Andrew Bennetts
andrew-pywin32 at puzzling.org
Tue Dec 16 20:56:36 EST 2003
On Tue, Dec 16, 2003 at 07:53:15PM -0500, Myddrin wrote:
[...using Queue.Queue for inter-thread communication...]
>
> Would using win32event module or the python condition class be more
> efficient, or are the locking classes utilized by Queue about as effiecient
> as anything else? Cross-platform solutions are preferred, but not required
> so if I can shave some cycles, I'll happily re-write the same code for the
> other platforms. [Well, ok...not happily... infact I'll whine and complain,
> but it would be worth it if I could cut my CPU usage in half or better.]
Have you profiled your code to find out where the time is being spent? It
wouldn't expect locking to be bottleneck in most code. Particularly in your
case, it sounds like there's very little lock contention at all -- you don't
sound like you have many threads all fighting for the same lock. It's
conceivable that if you have long queues, that Queue.Queue might be a
bottleneck due to all the memmoves.
But this is all guesswork. You really need to do some profiling to know
that you aren't wasting your time optimising something that only takes 0.1%
of the total time.
Another option is to just not worry about optimising yourself, and let psyco
<http://psyco.sf.net/> speed up your code for you.
-Andrew.
More information about the Python-win32
mailing list