Is it Python or is it C ?

Steve Holden sholden at bellatlantic.net
Wed Mar 8 19:39:39 CET 2000


Emile van Sebille wrote:
> 
> Don,
> 
> Once it exists in the interpreter as bytecode, isn't it
> *all* running as compiled C?  In which case, doesn't
> that transform the question to 'which preferred pydioms
> yield the best performing bytecode?'? <*1>

Well, actually, no.  At the very least, each bytecode operation
has to be used as the offset in a table of indirect procedure
calls.  Normally an interpreter will have a procedure for
each bytecode, although you can sometimes optimize the bytecode
streams considerably.

Then each operand's address has to be loaded and used to access
the operand (I'm going out on a limb here and assuming more
than I really know about the interpreter).

Both of these are operations which hardware performs on real
instructions without need of further cycles, so you do end up
with quite a lot of overhead even in a fast and efficient interpreter.

A further point is that you might think you could improve speed by
in-lining the code (i.e. replacing the bytecodes with the sequences
of machine instructions they perform).  In most interpreted systems,
these sequences are often large, and so you just end up in-lining
calls to the interpreter routines.  This saves a little time, but
still leaves you somewhat behind fully compiled code.

> 
> There's been a number of speed related code optimization
> threads that I've seen.  IIRC, most came to the conclusion
> that coding done in the easiest most natural way performed
> best when scaled against readability (i.e., significant further
> speed gains came only at the expense of perl-style coding ;-).
> 
A common trade-off in some languages (e.g. Perl).  However, good
optimization of any language is able to beat handcrafting most
of the time. (Opinion: please don't ask for statistics...)

> Anyway, I'd also love to see a compilation of optimized coding
> preferences along the lines of 'use x over y because z'.
> 
> Although-it's-fast-enough-for-my-needs-ly y'rs,
> 
> Emile van Sebille
> emile at fenx.com
> -------------------
> *1 <Would you English majors out there tell me if I really
> need two '?'s at the end there?>

Technically I think you only need one.  However, I suspect Americans
would disagree with me about where it should go, since in UK usage
the closing punctuation is also used to close the sentence, and
so we would write:

... to "which preferred pydioms yield the best performing bytecode?"

whereas I understand correct American usage would be:

... to "which preferred pydioms yield the best performing bytecode"?

Is-there-a-place-for-teachers-of-Python-as-a-second-language-ly y'rs - Steve

PS:  I have no idea where (if anywhere) the question mark should have gone
	in that sign-off line!
--
"If computing ever stops being fun, I'll stop doing it"



More information about the Python-list mailing list