Python is faster than C

Joe Mason joe at notcharles.ca
Sun Apr 4 00:24:45 EST 2004


In article <406F6020.F1361B55 at tunes.org>, Armin Rigo wrote:
> Joe Mason wrote:
>> > The reason is that the C implementation must use a generic '<' operator
>> > to compare elements, while the Psyco version quickly figures out that it
>> > can expect to find ints in the list; it still has to check this
>> > assumption, but this is cheap and then the comparison is done with a
>> > single machine instruction.
>> 
>> Why can't the C implementation do the same thing?
> 
> You could, if you wanted to optimize specifically lists of integers.  If
> you did the result would probably be really fast.  The problem is that
> you can only really special-case so many types: the C code has to deal
> with all cases without knowing which cases are likely.  The Psyco
> version quickly figures out that for this list it pays off to make a
> special case for integers; with another list, the machine code would be
> different, special-cased differently.

Ah, good point.  (In fact, not special-casing lots of things in the C
code is exactly what I was arguing against in my other post.)

Joe



More information about the Python-list mailing list