#include <iostream>
#include <thread>
#include <chrono>
class Timer {
public:
Timer()
{
start = std::chrono::high_resolution_clock::now();
}
~Timer()
{
auto end = std::chrono::high_resolution_clock::now();
std::chrono::duration<float> duration = end - start;
std::cout << "Timer take " << duration.count() * 1000 << "ms" << std::endl;
}
private:
std::chrono::time_point<std::chrono::steady_clock> start;
};
void PrintMsg()
{
Timer timer;
for (int i = 0; i < 100; i++) {
std::cout << "Hello !" << std::endl;
}
}
int main()
{
PrintMsg();
std::cin.get();
}
【C++】RARI高精度计时类
最新推荐文章于 2024-11-09 20:38:27 发布