Python Speed Question and Opinion

Paramjit Oberoi p_s_oberoi at hotmail.com
Tue Jun 8 15:33:54 CEST 2004


> Jacek already made this point, but I'll make it again.  Assembler
> is sometimes *not* the way to write the fastest code.  (Though
> sometimes it is.)  Optimizing compilers for some languages such as
> C can actually produce *faster* code by choosing combinations of
> opcodes and side-effects that even an assembly programmer would be
> nuts to use in most cases, largely because it would make the code
> even more obscure than it already is but also because they might not
> even think of it.

Very true, and I would replace the "sometimes not the way to write the
fastest code" with "almost never...".  Especially when optimizing code for
a modern processor, a compiler will be much better at reordering
instructions so that they pass through the execution pipeline more
smoothly.

If you are writing a critical 20-instruction inner loop and are willing to
spend hours, if not days, experimenting with different instruction
sequences, you may be able to get slightly better performance than the
code generated by the compiler; but in most other cases it's best to leave
it to the compiler.

-param



More information about the Python-list mailing list