Hello all, I just solved a relatively easy riddle, and I thought I'd share the results:
# Cython version of cputime(): cdef extern from "time.h": ctypedef unsigned long clock_t cdef clock_t clock() cdef enum: CLOCKS_PER_SEC ##### To use: ##### # # cdef clock_t start, end # cdef double cpu_time_used # start = clock() # # Do the work. # end = clock() # cpu_time_used = (<double> (end - start)) / CLOCKS_PER_SEC # ################### If you use this, you should check /usr/includes/sys/times.h or /usr/includes/sys/types.h to make sure that "unsigned long" is the right declaration for clock_t. Also note that "man clock" makes it seem as if CLOCKS_PER_SEC isn't very accurate: """ The clock() function conforms to ISO/IEC 9899:1990 (``ISO C90''). However, Version 2 of the Single UNIX Specification (``SUSv2'') requires CLOCKS_PER_SEC to be defined as one million. FreeBSD does not conform to this requirement; changing the value would introduce binary incompatibility and one million is still inadequate on modern processors. BSD June 4, 1993 BSD """ If you exclude the ticks to seconds conversion entirely, might be more truthful. Still very useful for profiling. -- Robert L. Miller http://www.rlmiller.org/ -- 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