我正在使用不包含 boost::timer 的 boost 1.46,还有什么其他方法可以为我的函数计时。
我目前正在这样做:
time_t now = time(0);
<some stuff>
time_t after = time(0);
cout << after - now << endl;
但它只是在几秒钟内给出答案,所以如果函数花费 < 1s 它会显示 0。
谢谢
最佳答案
在 linux 或 Windows 中:
#include <ctime>
#include <iostream>
int
main(int, const char**)
{
std::clock_t start;
start = std::clock();
// your test
std::cout << "Time: " << (std::clock() - start) / (double)(CLOCKS_PER_SEC / 1000) << " ms" << std::endl;
return 0;
}
祝你好运;)
关于c++ - 如何在没有 boost::timer 的情况下以毫秒为单位计时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15092504/