计时

包含< chrono >

作用:
能帮助查看程序运行时间

代码示例:

class Timer
{
     using namespace std::literals::chrono_literals;//duration命名空间
public:
Timer()
{
    auto start=std::chrono::high_resolution_clock::now();//获取当前时间
}
~Timer()
{
    auto end=std::chrono::high_resolution_clock::now();//获取当前时间
    std::duration<float> duration()=end-start;
    std::cout<<duration.count()*1000.0f<<endl;//毫秒为单位
}
  
  

}
int main()
{
using namaspce std::literals::chrono_literals//休眠函数用的
Timer a;
std::this_thread::sleep_for(1s);
}
posted @ 2024-07-15 09:53  Wzline  阅读(1)  评论(0编辑  收藏  举报