sqlite shell 报告 CPU 时间 : what are the units?

标签 sqlite shell

当使用带有 .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/

相关文章:

django -/在尝试写入只读数据库时出现OperationalError

mysql - Rails 迁移需要不可移植的 SQL

linux - 如何将(两个)管道指令的输出传递给文件?

linux - 期待 bash 脚本中的命令

linux - Linux中使用shell脚本的文件数量(如果没有输出错误就不应该出现)

linux - 我无法从 'script2.sh' 运行 'script1.sh'(它们在同一文件夹中并具有 755 权限)

linux - screen 远程分离时网络连接丢失

python - 使用 Kivy 创建 sqlite3 数据库

iphone - 在 iphone SQLite (FMDB) 中加载 10k+ 行

python - 导出到 CSV sqlite3 Python 后数据显示不正确