clock time in milliseconds into a c program

Daniel O'Connor doconnor at gsoft.com.au
Wed Jan 19 17:48:08 PST 2005


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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 187 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-hackers/attachments/20050120/5ec883de/attachment.bin


More information about the freebsd-hackers mailing list