[uClibc] clock() for long-running process
Joakim Tjernlund
joakim.tjernlund at lumentis.se
Tue May 11 13:04:38 UTC 2004
> >
> > I see, but using CPU time for measuring elapsed time is not very accurate, is it?
>
> We're talking about usage of clock() like
>
> start = clock();
> < do some work >
> elapsed = clock() - start;
>
> where the programmer _is_ attempting to measure cpu time.
ohh, sorry. My bad.
>
> > I can only find two way to measure elapsed time in Linux, the return
> > value from times()(needs scaling) or gettimeofday(). gettimeofday() has
> > the disadvantage that it may change time between polls.
>
> If you're trying to measure elapsed wall clock time on linux and you need
> only second accuracy, you can use the difference in system uptime.
>
> #include <sys/sysinfo.h>
>
> /* Return system uptime in seconds. */
>
> long uptime(void)
> {
> struct sysinfo info;
>
> sysinfo(&info);
>
> return info.uptime;
> }
OK, thanks. Hmm, why is info.uptime a long instead of an unsigned long? What happens when
info.uptime reaches negative values? I would guess that uptime just keeps counting until
it wraps to 0?
Jocke
More information about the uClibc
mailing list