Increasing time resolution of BOOST::progress timer

Posted by feelfree on Stack Overflow See other posts from Stack Overflow or by feelfree
Published on 2013-06-28T16:19:44Z Indexed on 2013/06/28 16:21 UTC
Read the original article Hit count: 240

Filed under:
|

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.

© Stack Overflow or respective owner

Related posts about c++

Related posts about boost