From: Craig H. <cr...@gu...> - 2006-01-25 22:41:43
|
Here's the function definition in uclibc: clock_t clock(void) { struct tms xtms; unsigned long t; times(&xtms); t = ((unsigned long) xtms.tms_utime) + xtms.tms_stime; #ifndef __UCLIBC_CLK_TCK_CONST # error __UCLIBC_CLK_TCK_CONST not defined! #elif ((CLOCKS_PER_SEC % __UCLIBC_CLK_TCK_CONST) == 0) /* CLOCKS_PER_SEC == k * __UCLIBC_CLK_TCK_CONST for some integer k >= 1. */ return ((t * (CLOCKS_PER_SEC/__UCLIBC_CLK_TCK_CONST)) & LONG_MAX); #else /* Unlike the previous case, the scaling factor is not an integer. * So when tms_utime, tms_stime, or their sum wraps, some of the * "visible" bits in the return value are affected. Nothing we * can really do about this though other than handle tms_utime and * tms_stime seperately and then sum. But since that doesn't really * buy us much, we don't bother. */ return ((((t / __UCLIBC_CLK_TCK_CONST) * CLOCKS_PER_SEC) + ((((t % __UCLIBC_CLK_TCK_CONST) * CLOCKS_PER_SEC) / __UCLIBC_CLK_TCK_CONST)) ) & LONG_MAX); #endif } That looks OK to me (we fall in the middle category btw, with CLOCKS_PER_SEC=1,000,000 and __UCLIBC_CLK_TCK_CONST = 100). If you program isn't doing much other than calling clock() and sleeping in a loop, then since the definition of clock() is based on *that process*'s CPU activity (user+system), and since while a process is waiting in sleep() it's not consuming any user or CPU time, "t" will only increment very very very slowly; which means that it unless you're actually doing some CPU usage in your app, clock() will appear to not be ticking. If you're looking for wallclock time instead of CPU-usage time, then check time() or gettimeofday() instead. C On Jan 25, 2006, at 1:25 PM, Bryan Adams wrote: > hi: > > has anyone used the calls to clock() (in time.h) successfully? i > seem to get the same number (50000 on some runs, 60000 on others) > on every call to clock(). thoughts? > > --bryan > > > ------------------------------------------------------- > This SF.net email is sponsored by: Splunk Inc. Do you grep through > log files > for problems? Stop! Download the new AJAX search engine that makes > searching your log files as easy as surfing the web. DOWNLOAD > SPLUNK! > http://sel.as-us.falkag.net/sel? > cmd=lnk&kid=103432&bid=230486&dat=121642 > _______________________________________________ > gumstix-users mailing list > gum...@li... > https://lists.sourceforge.net/lists/listinfo/gumstix-users |