From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f8c9b,259e99d494c8e68b X-Google-Attributes: gidf8c9b,public X-Google-Thread: 1014db,259e99d494c8e68b X-Google-Attributes: gid1014db,public X-Google-Thread: fee84,259e99d494c8e68b X-Google-Attributes: gidfee84,public X-Google-ArrivalTime: 1994-09-07 02:50:15 PST Newsgroups: comp.unix.osf.osf1,comp.lang.c,comp.unix.questions Path: nntp.gmd.de!xlink.net!howland.reston.ans.net!swiss.ans.net!gatech!swrinde!cs.utexas.edu!math.ohio-state.edu!jussieu.fr!univ-lyon1.fr!swidir.switch.ch!newsfeed.ACO.net!Austria.EU.net!EU.net!uunet!news.encore.com!lucifer!ashekhar From: ashekhar@luciferencore.com (Ajay Shekhar) Subject: Re: [Q] Accurately measure exec time of a process? Organization: Encore Computer Corperation Date: Tue, 6 Sep 1994 19:03:03 GMT Message-ID: References: <349aat$mer@pirates.cs.swt.edu> Sender: ashekhar@lucifer (Ajay Shekhar) Nntp-Posting-Host: lucifer.encore.com Xref: nntp.gmd.de comp.unix.osf.osf1:5174 comp.lang.c:60615 comp.unix.questions:38793 In article <349aat$mer@pirates.cs.swt.edu>, peng@pirates.cs.swt.edu (Wuxu Peng) writes: |> I have a C program (about 2,000 lines) implementing an approximate |> algorithm. The program has two phases. My question is: how can I |> accurately measure the execution time of each of the two phases? |> This measurement is important to demonstrate the usefulness of my |> algorithm. |> |> Thanks in advance. |> |> -- |> |> --wuxu peng (peng@pirates.cs.swt.edu) |> There is a macro called TIME_LOAD() which takes as input a long. This loads the cur time in seconds and micro seconds. You can use TIME_LOAD before and after your algorithm to measure the difference. Something like this #include "sys/time.h" main() { long time1, time2; ... TIME_LOAD(time1); algorithm body TIME_LOAD(time2); printf("Time Difference : %d secs : %d microseconds\n", ((struct timeval *)&time2->tv_sec - (struct timeval *)&time1->tv_sec)), ((struct timeval *)&time2->tv_usec - (struct timeval *)&time1->tv_usec))); You can't subtract the longs directly, because one half of the long word contains the time in seconds and the other in microseconds. You have to be careful with that. Hope it helps .. -- Ajay Shekhar (ashekhar@encore.com) Disclaimer : Nothing I ever say reflects Encore's opinions ...