Python from Wise Guy's Viewpoint

Lex Spoon lex at cc.gatech.edu
Tue Nov 4 01:46:22 CET 2003


Fergus Henderson <fjh at cs.mu.oz.au> writes:
>>If you are simply doing "x := y" then there is no checking required.
>
> Yes, we covered that already.  But that's not what is happening in
> the scenario that I was describing.  The scenario that I'm describing is
>
> 	Collection c;
>
> 	...
> 	foreach x in c do
> 		use(x);
>
> where use(x) might be a method call, a field access, or similar.
> For example, perhaps the collection is a set of integers, and you
> are computing their sum, so use(x) would be "sum += x".

I see.  "sum += x" would indeed tend to cause a lot of checks, but
then again the checks might well end up costing 0 overall CPU cycles.
The general technique of optimizing methods for common types, plus the
likelihood that a CPU will have multiple functional units, can make a
big difference.

Also, keep in mind that if this is a performance critical blotch of
code, then the programmer has the option of making "c" be a
specialized array or matrix type.


-Lex




More information about the Python-list mailing list