sqlite shell报告CPU时间:单位是多少?

时间:2013-11-27 22:48:59

标签: sqlite shell

当使用带有.timer on的Sqlite shell时,我得到的控制台打印如“CPU Time:user 0.062400 sys 0.015600”。如何将其转换为毫秒?是否有其他方法可以在Sqlite shell中以毫秒为单位测量总查询时间?

1 个答案:

答案 0 :(得分:5)

单位是秒。请参见参考: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。