[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Question about timing
On 08-Apr-2000 Steve Baker wrote:
> Erik wrote:
>> I'm pretty sure that the time is in processor ticks since the program
>> execution, it's not referring to the kind of processor time used in
>> 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.
hrm, indeed, I am in err. That'll teach me to listen to windows coders... I'm
going to theorize that the reason it worked for me is because my programs
didn't sleep, they continually rendered to acheive the fastest frame rate, so
the load that program was requesting was 1. I'm not sure how threading would
work, but in a single thread program that polls input and renders as fast as it
can, clock() does the job. gettimeofday() is probably a much better solution.
damnit, now I gotta fix that tutorial *sigh* :)
> Steve Baker http://web2.airmail.net/sjbaker1
> firstname.lastname@example.org (home) http://www.woodsoup.org/~sbaker
> email@example.com (work)
-Erik <firstname.lastname@example.org> [http://math.smsu.edu/~br0ke]
The opinions expressed by me are not necessarily opinions. In all
probability, they are random rambling, and to be ignored. Failure to ignore
may result in severe boredom or confusion. Shake well before opening. Keep
To unsubscribe, e-mail: email@example.com
For additional commands, e-mail: firstname.lastname@example.org