4 ms·
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 p
by durin42 17y ago
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()