sqlite shell reports CPU time: what are the units?

2019-08-12 07:32发布

问题:

When using the Sqlite shell with .timer on I get console prints like "CPU Time: user 0.062400 sys 0.015600". How do I convert that to milliseconds? Is there some other way to measure total query time in milliseconds in the Sqlite shell?

回答1:

The units are in seconds. See ref: https://github.com/freebsd/pkg/blob/master/external/sqlite/shell.c

snapshot of code from that page:

/* 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));
  }
}

If you would like to convert to milliseconds, multiply by 1000.



标签: sqlite shell