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.