Bytecode optimisation

Tim Peters tim_one at email.msn.com
Wed May 19 01:41:34 EDT 1999


Just popping in to spread some quick irony <wink>.

[Corran Webster, with a bytecode optimizer]
> ...
> The morals of this hack are:
> ...
>   * If you really need to make your code run faster, you're still better
>     off squeezing the Python source; if that doesn't work, then you
>     probably want to re-write in C.  However, there is hope for us lazy
>     coders in the future.
> ...
> binaryops = {
>     'BINARY_ADD': operator.add,
>     'BINARY_SUBTRACT': operator.sub,
> ...
>   }
>
> unaryops = {
>     'UNARY_POS': operator.pos,
>     'UNARY_NEG': operator.neg,
>     'UNARY_NOT': operator.not_
>   }
> ...
>     if repr(op) in binaryops.keys():
> ...
>     elif repr(op) in unaryops.keys():
> ...

If it can replace those last two with the (potentially) unboundedly faster

    if binaryops.has_key(repr(op)):
...
    elif unaryops.has_key(repr(op)):
...

you'll really have something <wink>.

No comment intended on the worth of the project or the code (haven't had
time to study it) -- just noting that dramatic speedups almost never come
from optimizers, but from writing the most appropriate code.

language-invariant-ly y'rs  - tim






More information about the Python-list mailing list