Increasing time resolution of BOOST::progress timer
- by feelfree
BOOST::progress_timer is a very useful class to measure the running time of a function. However, the default implementation of progress_timer is not accurate enough and a possible way of increasing time resolution is to reconstruct a new class as the following codes show:
#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(void)
{
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\n"
<<std::endl;
m_os.flags(old_flags);
m_os.precison(old_prec);
}
catch(...)
{
}
}
private:
std::ostream &m_os;
};
However, when I compile the codes with VC10, the following error appear:
'precison' : is not a member of 'std::basic_ostream<_Elem,_Traits>'
Any ideas? Thanks.