Re: how to get timestamp
"Attivilli Sirisha" <[email protected]>
| Newsgroups | gmane.comp.programming.cppug |
|---|---|
| Organization | JUNO |
| Message-ID | <[email protected]> |
Hi Raj,
You could use the timeval struct with gettimeofday to compute the time duration - as follows:
// ***************************************************************************
struct timeval curTime;
if (gettimeofday(&curTime,NULL) == -1) {
fprintf(stderr, "gettimeofday failed. Unable to compute the start time\n");
exit(-1);
}
struct timeval startTime = curTime;
// ...
// ... do your processing ...
// ...
if (gettimeofday(&curTime,NULL) == -1) {
fprintf(stderr, "gettimeofday failed. Unable to compute the end time\n");
exit(-1);
}
// Compute diffTime in microseconds
double diffTime = ((curTime.tv_sec*1000000 + curTime.tv_usec) -
(startTime.tv_sec*1000000+startTime.tv_usec));
// Convert back to milliseconds
diffTime /= 1000;
// ***************************************************************************
Hope that helps.
Thanks,
Sirisha.
----- Original Message -----
From: rajk116
To: [email protected]
Sent: Saturday, November 15, 2003 9:16 AM
Subject: [cppug] how to get timestamp
hi,
i need to calculate the time duration in msec of certain process in
c++.format is like
# find starttime (get timestamp)
# do someprocess ......
# find finishtime (get timestamp)
#calculate finishtime-starttime
please reply if anyone know how to get timestamp in milliseconds..
thanks in advance.
raj
Yahoo! Groups Sponsor
To unsubscribe from this group, send an email to:
[email protected]
Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.