On Thu, May 19, 2011 at 7:34 AM, Victor Stinner
<[email protected]> wrote:
> But it is slower whereas I read somewhere than generators are faster
> than loops.

Are you sure it wasn't that generator expressions can be faster than
list comprehensions (if the memory savings are significant)?

Or that a reduction function with a generator expression can be faster
than a module-level explicit loop (due to the replacement of
dict-based variable assignment with fast locals in the generator and C
looping in the reduction function)?

In general, as long as both are using fast locals and looping in
Python, I would expect inline looping code to be faster than the
equivalent generator (but often harder to maintain due to lack of
reusability).

Cheers,
Nick.

-- 
Nick Coghlan   |   [email protected]   |   Brisbane, Australia
_______________________________________________
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to