News for hackers. Stuff that matters.
Re:Python Performance Tips by durin42 on Monday January 04, 2010 @07:26PM (#1031537)
I'd offer up a word of caution though about generator comprehensions. They're much more expensive than list comprehensions in the small cases. In Mercurial, a patch came up to move some listcomps to gencomps, and it was rejected because it slowed things down. Sometimes the state required to manage the generator is more costly than evaluating everything.

Also, dot lookups in a loop are frequently a poor choice. Often you can get a huge speedup in a tight loop by changing

  for x in xrange(10000000): # or whatever
    foo.bar()
to

  foobar = foo.bar
  for x in xrange(10000000): # or whatever
    foobar()

There are no comments on this comment yet.