Click to See Complete Forum and Search --> : Precise C/C++ timer/stopwatch?
tecknophreak
07-09-2001, 04:16 PM
I thought I saw a good program lying around for a good timer/stopwatch that went to 1/1000 sec, but I couldn't find it. Yes I did the search and I looked through some which I thought might have it, but nothing.
If you have any information about the whereabouts of this "lost" program, post it up here. Thanks
[ 09 July 2001: Message edited by: tecknophreak ]
TheLinuxDuck
07-09-2001, 04:47 PM
There's a good bit of information on doing such a thing in C at this thread (http://www.linuxnewbie.org/cgi-bin/ubbcgi/ultimatebb.cgi?ubb=get_topic&f=14&t=003269). Check that out, and see if you can get it to do what you're looking to do.
tecknophreak
07-09-2001, 04:51 PM
That's exactly the one I was looking for. Sweet!! Thanks. Perfect way to end the day.
jemfinch
07-09-2001, 05:14 PM
Just as note, I really like my little timer function in Ocaml:
let time_loop n f =
let t = Unix.gettimeofday () in
for i=0 to n do
f ();
done;
Unix.gettimeofday () -. t;;
And then I can call it with something like this:
time_loop 100000 (fun () -> fact 10)
To test how long it takes my factorial function to find the factorial of 10 a hundred thousand times.
/me loves higher order functions :)
Jeremy
PS.: sorry to be off-topic, but to get back ontopic a bit, if you need to write your own timer function, remember to use "gettimeofday" because it has a much finer granularity than just "time".