Speed quirk: redundant line gives six-fold speedup

Bill Mill bill.mill at gmail.com
Thu Aug 25 13:30:32 EDT 2005


On 8/25/05, Mark Dickinson <dickinsm at verizon.net> wrote:
> I have a simple 192-line Python script that begins with the line:
> 
> dummy0 = 47
> 
> The script runs in less than 2.5 seconds.  The variable dummy0 is never
> referenced again, directly or indirectly, by the rest of the script.
> 
> Here's the surprise: if I remove or comment out this first line, the
> script takes more than 15 seconds to run.  So it appears that adding a
> redundant line produces a spectacular six-fold increase in speed!
> 
> (Actually, I had to add 29 dummy lines at the beginning of the code to
> get the speed increase; if any one of these lines is removed the
> running time reverts to around 15 seconds again.)
> 
> Questions:
<snip>

One of my own: what in the world made you think "maybe I'll add 29
dummy global variables to speed things up?"

It seems to work (>19x speedup on my machine), I'm just curious what
path you followed to get there.

And, finally, you should forward this to the python-dev list, if
somebody hasn't already. There are more people who know a ton about
python internals there.

Peace
Bill Mill
bill.mill at gmail.com



More information about the Python-list mailing list