Python from Wise Guy's Viewpoint

Fergus Henderson fjh at cs.mu.oz.au
Tue Nov 4 04:13:02 EST 2003


Lex Spoon <lex at cc.gatech.edu> writes:

>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.

Occaisionally, perhaps.  But I think that would be rare.

>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.

Even with an unlimited number of functional units, there's still the
extra CPU cycles to wait for instruction cache misses or page faults
caused by the greater code size.

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
The University of Melbourne         |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.




More information about the Python-list mailing list