BOOST CHRONO Steadycolock::now Analysis

Source: Internet
Author: User

Always feel that the time library of boost is not very good, of course, there may be I do not understand, so, the code out to see perhaps better, time processing, take the current time is really too common, and the various clock in the boost is not clear, however, the code can tell everything, As you can see from the code below, Steadyclock and Systemclock represent different counts at all. QueryPerformanceCounter This function takes the value of the hardware timer, so that the main use of the count, and the usual time now is actually different, where now is only the current count value, and Systemclock take is the system time , although converted to the file system time, this just changed the starting point of the next timer, so, if you want to take the current time or use Systemclock::now, of course, there may be other ways, this only after learning to summarize.

Win/chrono.cpp--------------------------------------------------------------////Copyright beman Dawes 2008//Cop Yright 2009-2010 Vicente J. Botet escriba//distributed under the Boost software License, Version 1.0.//see http://www.                                boost.org/license_1_0.txt//----------------------------------------------------------------------------//// Windows////--------------------------------------------------------- -------------------//#ifndef boost_chrono_detail_inlined_win_chrono_hpp#define Boost_chrono_detail_inlined_win_ Chrono_hpp#include <boost/detail/winapi/time.hpp> #include <boost/detail/winapi/timers.hpp> #include <boost/detail/winapi/getlasterror.hpp>namespace boost{namespace chrono{namespace chrono_detail{BOOST_CHRONO      _inline double get_nanosecs_per_tic () boost_noexcept {BOOST::d etail::winapi::large_integer_ freq; if (!boost::d etail::winapi::queryperformancefrequency (&freq)) return 0.0L; Return double (1000000000.0l/freq.  QuadPart); }} steady_clock::time_point Steady_clock::now () boost_noexcept {double nanosecs_per_tic = chrono_detail::get_nanosec    S_per_tic ();    Boost::d etail::winapi::large_integer_ pcount; if (nanosecs_per_tic <= 0.0L) {boost_assert (0 && "boost::chrono-get_nanosecs_per_tic Internal Erro      R ");    return Steady_clock::time_point ();    } unsigned times=0; while (! Boost::d etail::winapi::queryperformancecounter (&pcount)) {if (++times > 3) {BO        Ost_assert (0 && "Boost::chrono-queryperformancecounter Internal Error");      return Steady_clock::time_point (); }} return Steady_clock::time_point (steady_clock::d uration (static_cast<steady_clock::rep> (nanosecs_per_ TIC) * Pcount.  (QuadPart))); } #if!defined boost_chrono_dont_provide_hybrid_error_handling steady_clock::time_point Steady_clock::now (System:: Error_code & EC) {Double nanosecs_per_tic = chrono_detail::get_nanosecs_per_tic ();    Boost::d etail::winapi::large_integer_ pcount; if ((nanosecs_per_tic <= 0.0L) | |    (!boost::d etail::winapi::queryperformancecounter (&pcount))) {boost::d Etail::winapi::D word_ cause = ((nanosecs_per_tic <= 0.0L)?        Error_not_supported:boost::d etail::winapi::getlasterror ());                            if (boost_chrono_is_throws (EC)) {Boost::throw_exception (System::system_error ( Cause, Boost_chrono_system_category, "Chrono::steady_        Clock "));            } else {ec.assign (cause, boost_chrono_system_category);        Return Steady_clock::time_point (Duration (0)); }} if (!    Boost_chrono_is_throws (EC)) {ec.clear (); } return Time_point (Duration (static_cast<steady_clock::rep> (NanosEcs_per_tic * Pcount.  (QuadPart))); } #endif boost_chrono_inline system_clock::time_point system_clock::now () boost_noexcept {BOOST::d etail::winapi::fil    Etime_ ft;  Boost::d etail::winapi::getsystemtimeasfiletime (&ft); Never fails return system_clock::time_point (system_clock::d uration (((static_cast<__int64> Highdatetime) << 32) |  Ft.dwlowdatetime)-116444736000000000LL//-(134775LL*864000000000LL)); } #if!defined boost_chrono_dont_provide_hybrid_error_handling boost_chrono_inline system_clock::time_point system_    Clock::now (System::error_code & EC) {boost::d etail::winapi::filetime_ ft;  Boost::d etail::winapi::getsystemtimeasfiletime (&ft); Never fails if (!    Boost_chrono_is_throws (EC)) {ec.clear ();  } return System_clock::time_point (system_clock::d uration ((static_cast<__int64> (Ft.dwhighdatetime) << 32) | Ft.dwlowdatetime)-116444736000000000LL//-(134775LL*864000000000LL))); } #endif boost_chrono_inline std::time_t system_clock::to_time_t (const system_clock::time_point& t) BOOST_      NOEXCEPT {__int64 temp = T.time_since_epoch (). Count ();      Temp/= 10000000;  return static_cast<std::time_t> (temp); } boost_chrono_inline system_clock::time_point system_clock::from_time_t (std::time_t t) BOOST_NOEXCEPT {__int64 T      EMP = t;      Temp *= 10000000;  Return Time_point (Duration (temp)); }}//Namespace Chrono}//Namespace Boost#endif

  

BOOST CHRONO Steadycolock::now Analysis

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.