用C++测量经过的时间
Measure time elapsed in C++
可能重复:
linux 上的快速运行时间
如何测量函数在C++中执行所需的时间?如果我能把时间控制在几分之一毫秒,那将是最好的,但如果不能,精确到一毫秒就足够了。如果这意味着什么的话,我正在运行Ubuntu 11.04。
性能测量的最佳时钟是系统范围的实时时钟。在Linux中,可以将clock_gettime
函数与CLOCK_MONOTONIC
或CLOCK_MONOTONIC_RAW
一起使用。这些将给你纳秒的精度。
#include <ctime>
int main(){
clock_t start = clock();
// your program goes here
clock_t ends = clock();
cout << "Time elapsed: " << (double) (ends - start) / CLOCKS_PER_SEC << endl;
return 0;
}
相关文章:
- 为什么根据测量位置测量经过的时间时会有很大的不同?
- 如何比较两个经过的时间?
- 为什么这个经过的时间(帧时间)计算会锁定我的游戏
- 获取标准::未来<T>::wait_for的经过时间
- C++ 时间机器无法正确计算经过的时间量
- 填充 unordered_map (c++) 后 malloc 的经过时间
- 自当地时间上午8点以来,将时间经过的时间与Boost
- 如何获得Microsoft TTS演讲的经过的时间
- 获取自C++执行以来经过时间的最干净,最简单的方法
- 在 Linux 中,非常高的经过(挂钟)时间和低系统时间的含义
- 16.66ms 帧时间.当 sleep() 只经过整毫秒时,你如何获得完美的 60 fps
- 以格式化字符串的形式获取经过的时间
- 如何在C++中检查经过的时间和分配的内存
- 在visualc++2010中经过的时间
- 如何在没有计时器的情况下确定经过了多少时间
- 如何获得自SFML中按下键以来经过的时间
- 两个时间之间经过的时间,格式为24小时hh:mm:ss
- 如何从steady_clock返回经过的时间作为原始数据类型(double)
- 查找经过的时间
- 在经过时间后做某事C++SFML 2