* 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.)

--
Jakub Wilk
def for_from():
    for i from 0 <= i < 10:
        for j from 0 <= j < 10:
            print(i + j)
def for_range():
    for i in range(10):
        for j in range(10):
            print(i + j)
_______________________________________________
cython-devel mailing list
cython-devel@python.org
https://mail.python.org/mailman/listinfo/cython-devel

Reply via email to