在程序运行时,要记录一段指令或者整个程序运行时间,则可以使用boost里关于时间的简单处理程序,这些函数存放在timer.hppl里面,可以直接引入使用,无需其他编译工作,但是,在使用前,要引入“#include<boost/timer.hpp>”,在引用目录里面添加boost的根目录,如D:\boost_1_55_0\boost_1_55_0,这样,前面的头文件引用才会正确
#include<boost/timer.hpp>
#include<iostream>using namespace std;
using namespace boost;
int main()
{
timer t;
cout << "Max timeSpan:" << t.elapsed_max() / 3600 << "h" << endl;//timer的最大计时时间(小时)
cout << "min timespan:" << t.elapsed_min() << "s" << endl;//timer的最小计时单位
cout << "now time elapsed:" << t.elapsed() << "s" << endl;//从timer声明到当前位置的时间(毫秒)
getchar();
}
这是我首次接触boost,觉得很强大,至少以前觉得很难处理的记录时间问题可以简单解决,后面的知识一定很强大,Come on!!!