Speed quirk: redundant line gives six-fold speedup

MrJean1 MrJean1 at gmail.com
Thu Aug 25 22:04:21 CEST 2005

Two observations:

1 - The difference in run time with and without the dummy* globals is
due to a difference in the number of invokations of the search()
function: 1,140 resp. 27,530 in my environment.

To verify, just change the line

  def search():


  searches = 0
  def search():
      global searches
      searches += 1

and add at the very end

  print searches, "searches"

2 - The run times with and without the dummy* variables is equal(ly
slow) if the LLentry() class and min() function call are modified to be
independent of the object value.

Change line

  class LLentry: pass


  LLinst = 0
  class LLentry(object):
      def __init__(self):
          global LLinst
          LLinst += 1
          self.I = LLinst

and change line

    mm = min((c.S, c) for c in rowitems(h))[1].D


    mm = min((c.S, c.I, c) for c in rowitems(h))[2].D

/Jean Brouwers

More information about the Python-list mailing list