[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Question about timing

Erik wrote:

> I'm pretty sure that the time is in processor ticks since the program started
> execution, it's not referring to the kind of processor time used in calculating
> load (yeah, it's a pretty ambigious man page...). The function does what we
> need it to.

The man page says:

|    The clock() function returns an approximation of processor
|    time used by the program.

"time used by the program" sounds pretty conclusive to me.

Anyway, here's proof:

int main ()
  clock_t t1, t2 ;
  t1 = clock () ;
  sleep ( 20 ) ;
  t2 = clock () ;
  printf ( "%f seconds.\n", (float)(t2-t1)/(float)CLOCKS_PER_SEC ) ;

...that code prints zero (time used was less than a millionth of a
second - which is the resolution of clock()) and not 20 as you'd
expect if clock() was elapsed time rather than CPU time.

Steve Baker                  http://web2.airmail.net/sjbaker1
sjbaker1@airmail.net (home)  http://www.woodsoup.org/~sbaker
sjbaker@hti.com      (work)

To unsubscribe, e-mail: linuxgames-unsubscribe@sunsite.auc.dk
For additional commands, e-mail: linuxgames-help@sunsite.auc.dk