Using Python for programming algorithms
sturlamolden
sturlamolden at yahoo.no
Wed May 21 13:29:23 EDT 2008
On May 21, 12:01 pm, Bruno Desthuilliers <bruno.
42.desthuilli... at websiteburo.invalid> wrote:
> > C has proven very difficult to optimize, particularly because pointer
> > aliasing prevents efficient register allocation.
>
> Does this compare to optimizing something like Python ? (serious
> question, but I think I already know part of the answer).
In Python different references can alias the same object. But the
objects for which this is important in C, is typically elementary
types like ints and floats. Pointer aliasing has the consequence that
the compiler often cannot choose to keep an int or a float in a
register inside a tight loop. This will often have serious
consequences for numerical computing. But these elementary types are
immutable in Python, so Python is actually somewhat immune to this.
This is one of several reasons why RPython sometimes can be "faster
than C".
But there are other much more important issues if you are to generate
efficient machine code from Python, e.g. getting rid of redundant
attribute lookups.
More information about the Python-list
mailing list