C++类库之Boost库的学习
- timer类
由于精度原因,不适合于精度很高或时间跨度很大的地方。也不能很好的跨平台。调用elapsed_min()和elapsed_max()分别获取其精度,而且其精度根据平台会有变化。
progress_timer类继承与timer类,但是其有一个析构函数,析构的时候会自动调用elapsed()输出从构造到析构所消耗的时间,所以利用这个类来测时间是非常方便的。
#include "boost/thread.hpp"
#include "boost/timer.hpp"
#include "boost/progress.hpp"
#include "iostream"
using namespace std;
using namespace boost;
int _tmain(int argc, _TCHAR* argv[])
{
timer t;
cout << "max timespan : " << t.elapsed_max() / 3600 << "h" << endl;
progress_timer tt;
int i = 0;
while (i <= 100000000)
{
i++;
}
return 0;
}