Speed quirk: redundant line gives six-fold speedup

Jack Diederich jack at performancedrivers.com
Thu Aug 25 14:04:52 EDT 2005


On Thu, Aug 25, 2005 at 01:35:04PM -0400, Bill Mill wrote:
> On 8/25/05, Erik Max Francis <max at alcyone.com> wrote:
> > Mark Dickinson wrote:
> > 
> > > Questions:
> > >
> > > (1) Can anyone else reproduce this behaviour, or is it just some quirk
> > >     of my setup?
> > > (2) Any possible explanations?  Is there some optimization that kicks
> > >     in at a certain number of lines, or at a certain length of
> > >     bytecode?
> > > (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?
> > 
> 
> I did find, though, that if I remove all print statements from the
> program, the dummy and non-dummy variable versions take indentical
> time. Can others reproduce this?
> 
> I'm Investigating further...

I'm getting similarly freakish results.  I tried a little ghetto debugging
by putting a printf in dictobject.c's resize method and recompiling python.
Sadly I can't get the problem to reproduce itself with the new binary
(with or without the printf).  The Ubuntu default 2.4.1 is sometimes fast,
my hand compiled one (./configure && make) is always slow.

There are some very arcane low level things going on here.

sprat:~/src/Python-2.4.1# time ./python /tmp/odd.py > /dev/null
7.876u 0.008s 0:07.91 99.4%     0+0k 0+0io 0pf+0w
sprat:~/src/Python-2.4.1# time python /tmp/odd.py > /dev/null
1.813u 0.004s 0:01.77 102.2%    0+0k 0+0io 0pf+0w

sprat:~/src/Python-2.4.1# ./python
Python 2.4.1 (#5, Aug 25 2005, 13:55:44) 
[GCC 3.3.5 (Debian 1:3.3.5-8ubuntu2)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 

sprat:~/src/Python-2.4.1# python
Python 2.4.1 (#2, Mar 30 2005, 21:51:10) 
[GCC 3.3.5 (Debian 1:3.3.5-8ubuntu2)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 

No-idea-ly,

-jackdied



More information about the Python-list mailing list