Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-06-02 08:17:15

0001 //
0002 // APFEL++ 2017
0003 //
0004 // Author: Valerio Bertone: valerio.bertone@cern.ch
0005 //
0006 
0007 #pragma once
0008 
0009 #include "apfel/messages.h"
0010 
0011 #include <chrono>
0012 
0013 namespace apfel
0014 {
0015   /**
0016    * @brief The Timer class computes the time elapsed between start
0017    * and stop.
0018    */
0019   class Timer
0020   {
0021   public:
0022     /**
0023      * @brief The Timer default constructor.
0024      */
0025     Timer() { start(); }
0026 
0027     /**
0028      * @brief This function starts the timer.
0029      */
0030     void start() { _startTime = std::chrono::steady_clock::now(); }
0031 
0032     /**
0033      * @brief This function stops the timer and reports the elapsed
0034      * time in seconds since the last time the timer was started.
0035      */
0036     void stop(bool const& ForceDisplay = false)
0037     {
0038       auto end = std::chrono::steady_clock::now();
0039       auto diff = end - _startTime;
0040       if (GetVerbosityLevel() > 1 || ForceDisplay)
0041         printf("Time elapsed: %5.6f seconds\n", std::chrono::duration <double, std::milli> (diff).count() * 1e-3);
0042     }
0043 
0044   private:
0045     std::chrono::time_point<std::chrono::steady_clock> _startTime;
0046   };
0047 }