zoukankan      html  css  js  c++  java
  • boost 库之时间处理 (cpu_timer auto_cpu_timer)(timer,progress_timer, progress_display)

    boost目前推荐 cpu_timer  auto_cpu_timer

    #include <boost/timer/timer.hpp>
    View Code
    #include <boost/timer/timer.hpp>
     #include <memory>
     #include <vector>
     #include <string>
     #include <iostream>
     
     using namespace std;
     using namespace boost::timer;
     
     
     vector<string> createVector_98()
     {
         vector<string> vec;
         for (int i = 0; i < 10; ++i){
                 vec.emplace_back("helloworld");
         }
         return vec;
     }
     
     vector<string> createVector_11()
     {
         vector<string> vec;
         for (int i = 0; i < 100; ++i){
             vec.emplace_back("helloworld");
         }
         return move(vec);
     }
     
     int main()
     {
         const int TEST_TIMES = 100;
     
         vector<string> result;
     
         cpu_timer timer;
         timer.start();
         for (int i = 0; i < TEST_TIMES; ++i){
             result = createVector_98();
         }
         cout << "no move" << timer.format(6) << endl;
     
         timer.start(); // don't call resume()
         
         for (int i = 0; i < TEST_TIMES; ++i){
             result = createVector_11();
         }
         cout << "use move" << timer.format(6) << endl;
     }

    http://www.cnblogs.com/hdtianfu/archive/2012/09/14/2684217.html

    旧的库 timer <boost/timer.hpp>  <boost/progress.hpp>

    View Code
    #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;
    }
    View Code
    #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\n"
                    << 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;
    }
    View Code
    #include "boost/progress.hpp"
    #include "boost/thread.hpp"
     int _tmain(int argc, _TCHAR* argv[])
     {
         //在控制台上显示程序执行进度
         boost::progress_display t(1000);
         for (int i = 0; i < 1000; i++)
         {
             boost::this_thread::sleep(boost::posix_time::milliseconds( 1010 ) );
             ++t;
         }
    
         return 0;
     }

    http://blog.csdn.net/chollima/article/details/7536077

  • 相关阅读:
    关于文件上传组件国内外完美解决方案的调查
    WIN10 评估版 查看过期时间
    Using Android Phone to recover SD card formatted with DD command under linux
    JavaScript 字符串与数组互转,并保持数据去重、排序功能
    国内基于浏览器的在线截屏插件方案汇总分析
    VC6到VC2010,项目迁移错误
    CentOS 7 Install Adobe Flash Player
    地铁图快速寻路算法
    windows的cmd下的find命令比bash(win10下的Ubuntu的bash)下的grep比较
    APUE习题5.x
  • 原文地址:https://www.cnblogs.com/logitechlike/p/2833235.html
Copyright © 2011-2022 走看看