使用Sqlite shell时,.timer on我得到控制台打印,如"CPU Time:user 0.062400 sys 0.015600".如何将其转换为毫秒?是否有其他方法可以在Sqlite shell中以毫秒为单位测量总查询时间?
单位是秒.参见参考:https://github.com/freebsd/pkg/blob/master/external/sqlite/shell.c
该页面的代码快照:
/* Return the difference of two time_structs in seconds */
static double timeDiff(struct timeval *pStart, struct timeval *pEnd){
return (pEnd->tv_usec - pStart->tv_usec)*0.000001 +
(double)(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",
timeDiff(&sBegin.ru_utime, &sEnd.ru_utime),
timeDiff(&sBegin.ru_stime, &sEnd.ru_stime));
}
}
Run Code Online (Sandbox Code Playgroud)
如果要转换为毫秒,请乘以1000.