7 ms·
Not really. "range" returns a list, "xrange" returns an iterator. I assume that the list is much easier to reason about in a JIT. In python3, range is a type of
by MrMeker 12y ago
Not really. "range" returns a list, "xrange" returns an iterator. I assume that the list is much easier to reason about in a JIT. In python3, range is a type of its own and certainly more useful for in a JIT.
https://docs.python.org/3/library/stdtypes.html#typesseq-range https://docs.python.org/3/library/stdtypes.html#typesseq-ran...
https://docs.python.org/2/library/functions.html#range https://docs.python.org/2/library/functions.html#range
- mborch 12y agoHow is allocating and populating a Python list order to do a simple for loop in a tight inner loop not problematic? Neither CPython nor PyPy can optimize that out. As I said, this is assuming we're on Python 2.x.
- rguillebert 12y agoPyPy optimizes that out, you have a thing that looks exactly like a list, but is implemented differently under the hood