Per gcc 4.1.2 (on fedora core 8, at least), tv_usec and tv_sec are long
ints. Thus, the computation in timeDiff (see below) overflows if the
computation takes more than around 2147 seconds. I propose the
following patch to shell.c. (Alternatively, a test can be made to see
if the system support long longs, and continue to use usecs.)
-/* Return the difference of two time_structs in microseconds */
-static int timeDiff(struct timeval *pStart, struct timeval *pEnd){
- return (pEnd->tv_usec - pStart->tv_usec) +
- 1000000*(pEnd->tv_sec - pStart->tv_sec);
+/* Return the different of two time_structs in seconds */
+static float timeDiff(struct timeval *pStart, struct timeval *pEnd){
+ return (pEnd->tv_usec - pStart->tv_usec) / 1000000.0 +
+ (pEnd->tv_sec - pStart->tv_sec);
}
/*
** Print the timing results.
*/
static void endTimer(void){
if( enableTimer ){
struct rusage sEnd;
getrusage(RUSAGE_SELF, &sEnd);
printf("CPU Time: user %f sys %f\n",
- 0.000001*timeDiff(&sBegin.ru_utime, &sEnd.ru_utime),
- 0.000001*timeDiff(&sBegin.ru_stime, &sEnd.ru_stime));
+ timeDiff(&sBegin.ru_utime, &sEnd.ru_utime),
+ timeDiff(&sBegin.ru_stime, &sEnd.ru_stime));
}
}
Steve Friedman
_______________________________________________
sqlite-users mailing list
[email protected]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users