Hello everyone, I am not sure whether it is the correct place to ask a bug of gettimeofday here. Hello everyone, I found sometimes the time will not be increased, but will be decreased. It does not happen each time, but happens rarely. Here is my program and output, are there anything wrong. Output -------------------- begin second and micro-second is: 1155819609 -- 653911 print begin time 2006-08-17 13:00:09.653 end second and micro-second is: 1155819609 -- 635116 print end time 2006-08-17 13:00:09.635 -------------------- Source code -------------------- Code: struct timeval begin, end gettimeofday(&begin,NULL); // operations gettimeofday(&end,NULL); timeDiff (&begin, &end); void print_time (timeval tv) { struct tm* ptm; char time_string[40]; long milliseconds; /* Obtain the time of day, and convert it to a tm struct. */ ptm = localtime (&tv.tv_sec); /* Format the date and time, down to a single second. */ strftime (time_string, sizeof (time_string), "%Y-%m-%d %H:%M:%S", ptm); /* Compute milliseconds from microseconds. */ milliseconds = tv.tv_usec / 1000; /* Print the formatted time, in seconds, followed by a decimal point and the milliseconds. */ printf ("%s.%03ld\n", time_string, milliseconds); } long timeDiff(struct timeval* begin,struct timeval* end) { long milliSeconds=0; milliSeconds = (long)(1000L*(end->tv_sec - begin->tv_sec) + (end->tv_usec - begin->tv_usec)/1000L); if(milliSeconds <= 0) { printf ("begin second and micro-second is: %ld -- %ld \n", begin->tv_sec, begin->tv_usec); printf ("print begin time \n"); print_time (*begin); printf ("end second and micro-second is: %ld -- %ld \n", end->tv_sec, end->tv_usec); printf ("print end time \n"); print_time (*end); } return milliSeconds; } -------------------- thanks in advance, George ____________________________________________________________________________________ Do you Yahoo!? Everyone is raving about the all-new Yahoo! Mail beta. http://new.mail.yahoo.com