On Thu, Oct 15, 2015 at 2:26 PM, Jakub Wilk <jw...@jwilk.net> wrote: > * Stefan Behnel <stefan...@behnel.de>, 2015-10-11, 16:30: >> >> The syntax construct "for i from 0 <= i < 10" has been silently outdated >> for years. Can we start issuing a warning that normal range() loops are >> preferred? > > > Hmm. AFAICS, Cython doesn't aways optimize range() loops that well... For > the attached example code, Cython 0.23.4 generated nice for loops for the > for_from() function: > > for (__pyx_t_1 = 0; __pyx_t_1 < 10; __pyx_t_1++) { > ... > for (__pyx_t_3 = 0; __pyx_t_3 < 10; __pyx_t_3++) { > ... > > but not for the for_range() function: > > __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_range, __pyx_tuple_, NULL); > ... > ... > > (The problem goes away if cdef the iteration variables, which I should do > anyway, so it's not a big deal for me.)
Correct, if you don't cdef the iteration (or bounds) variable it doesn't know what size of int to use (e.g. you could be doing range(10**100, 10**100 + 10). Also, as you point out, the overhead of using a Python target variable (for either format) is larger than range vs. C for loop. _______________________________________________ cython-devel mailing list cython-devel@python.org https://mail.python.org/mailman/listinfo/cython-devel