Gowdy solver
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
sys/trackUsedTime.h
Go to the documentation of this file.
00001 /**
00002  *  @file      trackUsedTime.h
00003  *  @brief     Tracks the elapsed lifetime of an object.
00004  *  @author    Mikica Kocic
00005  *  @copyright GNU General Public License (GPLv3).
00006  */
00007 
00008 /** The high resolution clock time-point.
00009  */
00010 typedef std::chrono::time_point<std::chrono::high_resolution_clock> time_hr;
00011 
00012 /** Reports the elapsed time for the lifetime of the created object.
00013  */
00014 class TrackUsedTime
00015 {
00016     time_hr rt_born; //!< The realtime when the object was created
00017 
00018 public:
00019 
00020     TrackUsedTime ()
00021     {
00022         rt_born = std::chrono::high_resolution_clock::now ();
00023     }
00024 
00025     ~TrackUsedTime ()
00026     {
00027         slog << std::endl << "Elapsed: ";
00028         auto end = std::chrono::high_resolution_clock::now ();
00029         auto elapsed = std::chrono::duration_cast<std::chrono::milliseconds>
00030                        ( end - rt_born ).count ();
00031         if ( elapsed < 1e3 ) {
00032             slog << elapsed << " ms" << std::endl;
00033         }
00034         else {
00035             slog << std::setprecision(3) << 1e-3 * elapsed << " s" << std::endl;
00036         }
00037     }
00038 };
00039