Dear Mikael, dear Carl, On May 20, 6:55 pm, Carl Witty <[EMAIL PROTECTED]> wrote:
> In this last case, presumably the C compiler has removed the loop > altogether ... hence, a better example is the following: def Pyloop(n): x=0 for i in range(n): x = x+i return x and the other functions accordingly. But the timings are puzzling for me: sage: timeit('x=Pyloop(10^6)') 5 loops, best of 3: 91.4 ms per loop sage: timeit('x=FakeCyloop(10^6)') 5 loops, best of 3: 40.2 ms per loop sage: timeit('x=Cyloop(10^6)') 5 loops, best of 3: 42.1 ms per loop sage: timeit('x=FullCyloop(10^6)') # defining x as long 625 loops, best of 3: 1.38 ms per loop So, although the loop isn't removed by the compiler, x being "long" improves the time considerably. Question: Why is FakeCyloop slightly *faster* than Cyloop (here we have "cdef int i")? I thought that explicitly int-declaring the running variable in a loop makes it faster? Yours Simon --~--~---------~--~----~------------~-------~--~----~ To post to this group, send email to sage-devel@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-devel URLs: http://www.sagemath.org -~----------~----~----~----~------~----~------~--~---