【发布时间】:2021-03-14 10:03:48
【问题描述】:
我在编程方面经验丰富,但对 C++ 很陌生。我正在尝试测量运行代码所需的时间。将来我可能会编写可能需要数小时/数天才能完成的代码。因此,了解计时时间测量的限制对我来说很重要。以毫秒为单位的精度应该足够了。
我可以测量的最长时间是多少?
我使用了以下代码,如果可以改进,请告诉我:
#include <chrono>
using namespace std::chrono;
auto start = high_resolution_clock::now();
// calculations here
auto finish = high_resolution_clock::now();
duration<double> elapsed = finish - start; // elapsed time in seconds
cout << elapsed.count();
【问题讨论】:
标签: c++ time chrono measurement