Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:52:54

0001 //  boost/timer/timer.hpp  -------------------------------------------------------------//
0002 
0003 //  Copyright Beman Dawes 1994-2007, 2011
0004 
0005 //  Distributed under the Boost Software License, Version 1.0.
0006 //  See http://www.boost.org/LICENSE_1_0.txt
0007 
0008 #ifndef BOOST_TIMER_TIMER_HPP                  
0009 #define BOOST_TIMER_TIMER_HPP
0010 
0011 #include <boost/timer/config.hpp>
0012 #include <boost/cstdint.hpp>
0013 #include <string>
0014 #include <cstring>
0015 #include <ostream>
0016 
0017 #include <boost/config/abi_prefix.hpp> // must be the last #include
0018 
0019 #   if defined(_MSC_VER)
0020 #     pragma warning(push)           // Save warning settings
0021 #     pragma warning(disable : 4251) // disable warning: class 'std::basic_string<_Elem,_Traits,_Ax>'
0022 #   endif                            // needs to have dll-interface...
0023 
0024 //--------------------------------------------------------------------------------------//
0025 
0026 namespace boost
0027 {
0028 namespace timer
0029 {
0030   class cpu_timer;
0031   class auto_cpu_timer;
0032 
0033   typedef boost::int_least64_t nanosecond_type;
0034 
0035   struct cpu_times
0036   {
0037     nanosecond_type wall;
0038     nanosecond_type user;
0039     nanosecond_type system;
0040 
0041     void clear() { wall = user = system = 0; }
0042   };
0043       
0044   const short         default_places = 6;
0045 
0046   BOOST_TIMER_DECL
0047   std::string format(const cpu_times& times, short places, const std::string& format); 
0048 
0049   BOOST_TIMER_DECL
0050   std::string format(const cpu_times& times, short places = default_places); 
0051 
0052 //  cpu_timer  -------------------------------------------------------------------------//
0053 
0054   class BOOST_TIMER_DECL cpu_timer
0055   {
0056   public:
0057 
0058     //  constructor
0059     cpu_timer() BOOST_NOEXCEPT                                   { start(); }
0060 
0061     //  observers
0062     bool          is_stopped() const BOOST_NOEXCEPT              { return m_is_stopped; }
0063     cpu_times     elapsed() const BOOST_NOEXCEPT;  // does not stop()
0064     std::string   format(short places, const std::string& format) const
0065                         { return ::boost::timer::format(elapsed(), places, format); }
0066     std::string   format(short places = default_places) const
0067                         { return ::boost::timer::format(elapsed(), places); }
0068     //  actions
0069     void          start() BOOST_NOEXCEPT;
0070     void          stop() BOOST_NOEXCEPT;
0071     void          resume() BOOST_NOEXCEPT; 
0072 
0073   private:
0074     cpu_times     m_times;
0075     bool          m_is_stopped;
0076   };
0077 
0078 //  auto_cpu_timer  --------------------------------------------------------------------//
0079 
0080   class BOOST_TIMER_DECL auto_cpu_timer : public cpu_timer
0081   {
0082   public:
0083 
0084     //  Explicit defaults for os are not provided to avoid including <iostream>, which has
0085     //  high costs even when the standard streams are not actually used. Explicit defaults
0086     //  for format are not provided to avoid order-of-dynamic-initialization issues with a
0087     //  std::string.
0088 
0089     explicit auto_cpu_timer(short places = default_places);                          // #1
0090              auto_cpu_timer(short places, const std::string& format);                // #2
0091     explicit auto_cpu_timer(const std::string& format);                              // #3
0092              auto_cpu_timer(std::ostream& os, short places,
0093                             const std::string& format)                               // #4
0094                                    : m_places(places), m_os(&os), m_format(format)
0095                                    { start(); }
0096     explicit auto_cpu_timer(std::ostream& os, short places = default_places);        // #5
0097              auto_cpu_timer(std::ostream& os, const std::string& format)             // #6
0098                                    : m_places(default_places), m_os(&os), m_format(format)
0099                                    { start(); }
0100 
0101    ~auto_cpu_timer();
0102 
0103    //  observers
0104    //    not particularly useful to users, but allow testing of constructor
0105    //    postconditions and ease specification of other functionality without resorting
0106    //    to "for exposition only" private members.
0107    std::ostream&       ostream() const       { return *m_os; }
0108    short               places() const        { return m_places; }
0109    const std::string&  format_string() const { return m_format; }
0110 
0111     //  actions
0112     void   report(); 
0113 
0114   private:
0115     short           m_places;
0116     std::ostream*   m_os;      // stored as ptr so compiler can generate operator= 
0117     std::string     m_format;  
0118   };
0119    
0120 } // namespace timer
0121 } // namespace boost
0122 
0123 #   if defined(_MSC_VER)
0124 #     pragma warning(pop) // restore warning settings.
0125 #   endif 
0126 
0127 #include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas
0128 
0129 #endif  // BOOST_TIMER_TIMER_HPP