Add a note on optimizing the itertools recipes for production.

This commit is contained in:
Raymond Hettinger 2010-03-28 18:08:15 +00:00
parent 5b027f87b5
commit d282b931a3
1 changed files with 6 additions and 0 deletions

View File

@ -784,3 +784,9 @@ which incur interpreter overhead.
except exception:
pass
Note, many of the above recipes can be optimized by replacing global lookups
with local variables defined as default values. For example, the
*dotproduct* recipe can be written as::
def dotproduct(vec1, vec2, sum=sum, imap=imap, mul=operator.mul):
return sum(imap(mul, vec1, vec2))