Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:59:12

0001 //
0002 // ********************************************************************
0003 // * License and Disclaimer                                           *
0004 // *                                                                  *
0005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
0006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
0007 // * conditions of the Geant4 Software License,  included in the file *
0008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
0009 // * include a list of copyright holders.                             *
0010 // *                                                                  *
0011 // * Neither the authors of this software system, nor their employing *
0012 // * institutes,nor the agencies providing financial support for this *
0013 // * work  make  any representation or  warranty, express or implied, *
0014 // * regarding  this  software system or assume any liability for its *
0015 // * use.  Please see the license in the file  LICENSE  and URL above *
0016 // * for the full disclaimer and the limitation of liability.         *
0017 // *                                                                  *
0018 // * This  code  implementation is the result of  the  scientific and *
0019 // * technical work of the GEANT4 collaboration.                      *
0020 // * By using,  copying,  modifying or  distributing the software (or *
0021 // * any work based  on the software)  you  agree  to acknowledge its *
0022 // * use  in  resulting  scientific  publications,  and indicate your *
0023 // * acceptance of all terms of the Geant4 Software license.          *
0024 // ********************************************************************
0025 //
0026 // G4Timer
0027 //
0028 // Class description:
0029 //
0030 // Class for timer objects, able to measure elasped user/system process time.
0031 //
0032 // Note: Uses <sys/times.h> & <unistd.h> - POSIX.1 defined
0033 //       If used, this header must be included in the source (.cc) file and it
0034 //       must be the first header file to be included!
0035 //
0036 // Member functions:
0037 //
0038 // G4Timer()
0039 //   Construct a timer object
0040 // Start()
0041 //   Start timing
0042 // Stop()
0043 //   Stop timing
0044 // G4bool IsValid()
0045 //   Return true if have a valid time (ie start() and stop() called)
0046 // G4double GetRealElapsed()
0047 //   Return the elapsed real time between last calling start() and stop()
0048 // G4double GetSystemElapsed()
0049 //   Return the elapsed system time between last calling start() and stop()
0050 // G4double GetUserElapsed()
0051 //   Return the elapsed user time between last calling start() and stop()
0052 //
0053 // Operators:
0054 //
0055 // std::ostream& operator << (std::ostream& os, const G4Timer& t);
0056 //   Print the elapsed real,system and usertimes on os. Prints **s for times
0057 //   if !IsValid
0058 //
0059 // Member data:
0060 //
0061 // G4bool fValidTimes
0062 //   True after start and stop have both been called more than once and
0063 //   an equal number of times
0064 // clock_t fStartRealTime,fEndRealTime
0065 //   Real times (arbitrary time 0)
0066 // tms fStartTimes,fEndTimes
0067 //   Timing structures (see times(2)) for start and end times
0068 
0069 // Author: P.Kent, 21.08.95 - First implementation
0070 // Revision: G.Cosmo, 29.04.97 - Added timings for Windows
0071 // --------------------------------------------------------------------
0072 #ifndef G4TIMER_HH
0073 #define G4TIMER_HH 1
0074 
0075 #if !(defined(WIN32) || defined(__MINGW32__))
0076 #  include <sys/times.h>
0077 #  include <unistd.h>
0078 #else
0079 #  include <time.h>
0080 #  define _SC_CLK_TCK 1
0081 
0082 extern "C"
0083 {
0084   int sysconf(int);
0085 };
0086 
0087 // Structure returned by times()
0088 
0089 struct tms
0090 {
0091   clock_t tms_utime;  /* user time */
0092   clock_t tms_stime;  /* system time */
0093   clock_t tms_cutime; /* user time, children */
0094   clock_t tms_cstime; /* system time, children */
0095 };
0096 
0097 extern "C"
0098 {
0099   extern clock_t times(struct tms*);
0100 };
0101 #endif /* WIN32 */
0102 
0103 #include "G4Types.hh"
0104 #include "G4ios.hh"
0105 
0106 #include <chrono>
0107 
0108 class G4Timer
0109 {
0110  public:
0111   inline void Start();
0112   inline void Stop();
0113   inline G4bool IsValid() const;
0114   inline const char* GetClockTime() const;
0115   G4double GetRealElapsed() const;
0116   G4double GetSystemElapsed() const;
0117   G4double GetUserElapsed() const;
0118 
0119  private:
0120   G4bool fValidTimes{false};
0121   using clock_type = std::chrono::high_resolution_clock;
0122   std::chrono::time_point<clock_type> fStartRealTime, fEndRealTime;
0123   tms fStartTimes, fEndTimes;
0124 };
0125 
0126 std::ostream& operator<<(std::ostream& os, const G4Timer& t);
0127 
0128 #include "G4Timer.icc"
0129 
0130 #endif