On Dec 11, 2008, at 1:13 AM, Stefan Behnel wrote: > Robert Bradshaw wrote: >> %cython >> >> cdef foo_c(): >> pass >> >> def do_loop_c_call(int n, int m): >> cdef int i, j >> for i in range(n): >> for j in range(m): >> foo_c() >> [...] >> sage: time do_loop_c_call(5000, 500) >> CPU time: 0.00 s, Wall time: 0.00 s >> >> The moral of the story is that the loop overhead can be reduced to >> essentially a clock cycle or two per iteration (nanoseconds) > > Have you looked at the assembly that the above code compiles into? I > wouldn't be surprised if the C compiler inlined the call to foo_c > (), and > then removed the entire loop as useless code.
Note: sage: time do_loop_c_call(5000, 50000) # 100x anything above CPU time: 0.22 s, Wall time: 0.22 s (It can't optimize away the function call because of the implicit incref/decref None. If it was cdef int foo_c() then it would probably have optimized the whole thing away. - Robert _______________________________________________ Cython-dev mailing list [email protected] http://codespeak.net/mailman/listinfo/cython-dev
