Calculating time in LINUX in milliseconds and Seconds. We should include sys/time.h header file and the remaining sample code is
struct timeval start;
we wil be using gettimeofday system call whose syntax is
int gettimeofday(struct timeval *tv, struct timezone *tz); where
struct timeval
{
time_t tv_sec;···············/* seconds */
suseconds_t tv_usec;······/* microseconds */
};
/* To calculate time in seconds*/
gettimeofday(&start, NULL);
starttime = start.tv_sec + start.tv_usec/1000000;
/* To calculate time in milliseconds*/
gettimeofday(&start, NULL);
starttime = start.tv_sec*1000 + start.tv_usec/1000;
No comments :
Post a Comment
Your comments are moderated