当前位置:网站首页>timer使用备注

timer使用备注

2022-06-24 06:44:00 雾散睛明

timer使用备注
windows 平台:
CreateWaitableTimer
SetWaitableTimer

boost库:
timer
progress_timer
progress_display

timer相当于一个计时器(毫秒级),同时提供相关的操作函数供程序员使用。

//引入头文件,.hpp为.h+cpp,这样的文件不需要预先编译

#include<boost/timer.hpp>
#include<iostream>
using namespace std;
//使用boost命名空间
using namespace boost;
int main()
{
    
	timer t;//定义一个计时器,从定义出开始计时
	//计时器最大计时时间
	cout << "max timespan:" << t.elapsed_max() / 3600 << "h" << endl;
	//计时器最小计时时间
	cout << "min timespan:" << t.elapsed_min() << "s" << endl;
	//输出计时器当前的计时时间
	cout << "now time elapsed" << t.elapsed() << "s" << endl;
}

timer还有一个常用的方法如下:
//重新计时
void restart(){_start_time = std::clock();}

progress_timer 在析构的时候 自动调用elspsed()
同时progress_timer还可以配合stringstream来使用,可以将信息输出在stringstream中
stringstream s;
{
progress_timer t(s);//出作用域后会将信息输入在s中,而不是打印出来
}
cout << s.str()<< endl;//可以通过s将t的计时信息进行打印

progress_display 具有一个显示的功能
可参考:https://blog.csdn.net/qq_42214953/article/details/105841155

原网站

版权声明
本文为[雾散睛明]所创,转载请带上原文链接,感谢
https://blog.csdn.net/qq_25160759/article/details/116239133

随机推荐