On Thu, 20 Jan 2005 11:14, Marco Trentini wrote: > Hi, I need to clock the function execution time into a C > program. I know /usr/include/time.h library but I need to > clock the time in milliseconds.
How about..
struct timeval then, now;
gettimeofday(&then, NULL);
somefunction();
gettimeofday(&now, NULL);
timespecsub(&now, &then);
printf("function took %ld milliseconds to run\n", now.tv_sec * 1000 +
now.tv_usec / 1000);
--
Daniel O'Connor software and network engineer
for Genesis Software - http://www.gsoft.com.au
"The nice thing about standards is that there
are so many of them to choose from."
-- Andrew Tanenbaum
GPG Fingerprint - 5596 B766 97C0 0E94 4347 295E E593 DC20 7B3F CE8C
pgp3HXxBPZ8Hu.pgp
Description: PGP signature

