当使用带有 .timer on
的 Sqlite shell 时我得到控制台打印,如“CPU 时间:用户 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));
}
}
如果您想转换为毫秒,请乘以 1000。
关于sqlite shell 报告 CPU 时间 : what are the units?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20254603/