python speed

Dave Brueck dave at pythonapocrypha.com
Wed Nov 30 11:24:09 EST 2005


Steven Bethard wrote:
> David Rasmussen wrote:
> 
>>Harald Armin Massa wrote:
>>
>>
>>>Dr. Armin Rigo has some mathematical proof, that High Level Languages
>>>like esp. Python are able to be faster than low level code like
>>>Fortran, C or assembly.
>>
>>Faster than assembly? LOL... :)
> 
> 
> I think the claim goes something along the lines of "assembly is so hard 
> to get right that if you can automatically generate it from a HLL, not 
> only will it be more likely to be correct, it will be more likely to be 
> fast because the code generator can provide the appropriate optimizations".
> 
> OTOH, you can almost certainly take automatically generated assembly 
> code and make optimizations the code generator wasn't able to, thanks to 
> knowing more about the real semantics of the program.

Yeah, but the other important part of the claim has to do with just that: the 
real [runtime] semantics of the program.

Hand optimization happens before runtime, obviously, whereas the HLL->assembly 
conversion can happen once the program is running and more info is known about 
the actual sets of data being operated on, the frequence of function calls, i.e. 
where the need for optimization actually exists. The optimization could even 
happen multiple times to adapt over time, or to allow multiple optimizations for 
different classes of data so that the code that actually executes is highly 
specialized.

So, yeah, knowledge of the runtime behavior can allow a hand-optimized version 
to run faster than a static, automatically-generated version, but knowledge of 
the runtime behavior could also allow a dynamic code generator to even beat the 
hand-optimized version.

-Dave



More information about the Python-list mailing list