如何使用gettimeofday()来获取运行时间
How to use gettimeofday() to get the run time?
我的问题是"t1.tv_usec-t0.tv_usec"的含义是什么?我觉得这部分没用,"* 1000000"是什么意思?
gettimeofday(&t0, 0);
/* ... */
gettimeofday(&t1, 0);
long elapsed = (t1.tv_sec-t0.tv_sec)*1000000 + t1.tv_usec-t0.tv_usec;
将总时间转换为μs,因为tv_usec
是总时间的微秒部分,tv_sec
是秒部分,您需要将秒数乘以1000000
来获得它们所代表的μs的数量
相关文章:
- KMP算法和LPS表构造的运行时间
- 如何计算Big-O表示法中的平均渐近运行时间
- 用时钟测量程序的运行时间
- c++ 11 如何获取系统时间?
- 如何以毫秒为单位获取开始时间和 now() 之间的毫秒差异(以 C++为单位?
- 如何减少代码的运行时间以对齐文本?
- 我的 c++ 应用程序中的运行时间从 0 增加到 60 太快了(例如一毫秒或一微秒)
- 使用 Qt 测量过程的实际运行时间
- C++程序以获取当前时间
- 如何执行用 C++ 编写的程序的运行时间?
- 无限运行时间
- 在Hackerearth上获取运行时错误(SIGSEGV),无法找出代码中的问题
- 使用C++中的put_time以毫秒精度获取当前时间
- 如何优化C++键值程序以获得更快的运行时间
- 在C 中获取功能的运行时间
- 运行时间错误:程序跳过提示,以获取第二名和第三个名称
- 如何从boost::timer::cpu_timer获取以秒为单位的运行时间
- 如何使用gettimeofday()来获取运行时间
- 在Unix类系统上以秒或毫秒为单位获取正常运行时间
- 使用性能计数器获取正常运行时间的权限问题