boostライブラリの時間処理(timer,progress_timer,progress_display)
1.timer
2.progress_timer
3.progress_display
#include "stdafx.h"
#include <iostream>
#include "boost/timer.hpp"
//using namespace boost;
int _tmain(int argc, _TCHAR* argv[])
{
boost::timer t;
std::cout << t.elapsed_max() << std::endl; //
std::cout << t.elapsed_min() << std::endl; // ,
std::cout << t.elapsed() << std::endl; //
return 0;
}
2.progress_timer
#include "stdafx.h"
#include "boost/progress.hpp"
#include "boost/static_assert.hpp"
//
template<int N = 2>
class new_progress_timer:public boost::timer
{
public:
new_progress_timer(std::ostream& os = std::cout)
: m_os(os)
{
BOOST_STATIC_ASSERT(N >= 0 && N <= 10);
}
~new_progress_timer()
{
try
{
std::istream::fmtflags old_flags = m_os.setf(std::istream::fixed, std::istream::floatfield);
std::streamsize old_prec = m_os.precision(N);
m_os << elapsed() << " s
"
<< std::endl;
m_os.flags(old_flags);
m_os.precision(old_prec);
}
catch (...)
{
}
}
private:
std::ostream& m_os;
};
int _tmain(int argc, _TCHAR* argv[])
{
new_progress_timer<10> t;
::Sleep(1010);
return 0;
}
3.progress_display
#include "stdafx.h"
#include "boost/progress.hpp"
int _tmain(int argc, _TCHAR* argv[])
{
//
boost::progress_display t(1000);
for (int i = 0; i < 1000; i++)
{
::Sleep(10);
++t;
}
return 0;
}