sqlite shell 报告 CPU 时间:单位是什么? [英] sqlite shell reports CPU time: what are the units?

查看:44
本文介绍了sqlite shell 报告 CPU 时间:单位是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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?

推荐答案

单位为秒.见参考: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.

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

这篇关于sqlite shell 报告 CPU 时间:单位是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆