Speed quirk: redundant line gives six-fold speedup

jay graves jaywgraves at gmail.com
Thu Aug 25 19:31:03 CEST 2005

Mark Dickinson wrote:
> Questions:
> (1) Can anyone else reproduce this behaviour, or is it just some quirk
>     of my setup?

yes.  I get 7 sec vs 1 sec on my laptop.

> (2) Any possible explanations?  Is there some optimization that kicks
>     in at a certain number of lines, or at a certain length of
>     bytecode?

I don't think there are any optimizations at play here.

> (3) If (2), is there some way to force the optimization, so that I can
>     get the speed increase without having to add the extra lines?

When I start a python interpreter and import the module the speed
difference disappears and it actually gets about two times faster.

I don't have a solution but I admire the problem. [1]


[1] Google tells me that this is probably attributable to Ashleigh

More information about the Python-list mailing list