当使用SQLite的外壳.timer on
我得到控制台打印像“CPU时间:用户0.062400 SYS 0.015600”。 如何将其转换成毫秒? 有测量以毫秒为单位的总查询时间在SQLite的外壳一些其他的方式?
Answer 1:
单位为秒。 见参考文献: 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 reports CPU time: what are the units?