A more accurate follow-up to my hurried post of a few hours ago. Timings on the same machine for a more truthful speed comparison, now in reality "just" a 150x speed-up due to Cython.
Triple-braces delimit compute cells in the notebook. Notice that the "%cython" block automatically produces the C output and an HTML file of the source, where you can click on individual lines to see the per- line conversion to C, with less-efficient conversions highlighted in yellow. Hopefully an approach with very fast code like this for internal computations, plus fast conversions to Sage types at the user-level might make for a good combination. Developing with the Sage types until you get it right, and then optimizing replacements with Cython code is a good strategy as well. I'm sure others with more experience will have more knowledgeable opinions or solutions. It'll be great to see some matroid theory available in Sage - thanks for your work on this. Rob {{{ def intersect_python(): t = 0 for s1 in range(0,2**9): for s2 in range(0,2**9): if s1 & s2: t += 1 return t }}} {{{ timeit("intersect_python()", number=100) }}} 100 loops, best of 3: 31.5 ms per loop {{{ %cython def intersect_cython(): cdef Py_ssize_t t, s1, s2 t = 0 for s1 in range(0,2**9): for s2 in range(0,2**9): if s1 & s2: t += 1 return t }}} {{{ timeit("intersect_cython()", number=10000) }}} 10000 loops, best of 3: 205 µs per loop -- To post to this group, send an email to sage-devel@googlegroups.com To unsubscribe from this group, send an email to sage-devel+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-devel URL: http://www.sagemath.org