On Wed, Jul 14, 2010 at 1:21 PM, Robert Miller <r...@rlmiller.org> wrote: > 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.
Thanks for this. Btw, I just revived this cython based line profiler: http://github.com/certik/line_profiler but it only works for python code. Ondrej -- 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