[219] | 1 | // This may look like C code, but it is really -*- C++ -*-
|
---|
| 2 | //
|
---|
[3274] | 3 | // $Id: ctimer.h,v 1.5 2007-07-06 12:54:12 ansari Exp $
|
---|
[219] | 4 | //
|
---|
| 5 |
|
---|
| 6 |
|
---|
| 7 | #ifndef CTIMER_SEEN
|
---|
| 8 | #define CTIMER_SEEN
|
---|
| 9 |
|
---|
[895] | 10 | #include "machdefs.h"
|
---|
[219] | 11 | #include <sys/types.h>
|
---|
| 12 | #include <time.h>
|
---|
[2322] | 13 | #include <iostream>
|
---|
[219] | 14 | #include <stdio.h>
|
---|
[895] | 15 | #include <string>
|
---|
[219] | 16 |
|
---|
| 17 | // <summary> Permet de chronometrer des fonctions. </summary>
|
---|
[3274] | 18 | // Class Timer qui memorise l'heure de sa creation, et le temps CPU.
|
---|
[219] | 19 | // A la fin du bloc ou de la procedure, l'objet est detruit,
|
---|
| 20 | // et son destructeur affiche le temps ecoule.
|
---|
| 21 |
|
---|
[895] | 22 | namespace SOPHYA {
|
---|
| 23 |
|
---|
| 24 | //! Simple chronometer class
|
---|
[241] | 25 | class Timer {
|
---|
[219] | 26 | public:
|
---|
| 27 | // L'objet memorise le temps CPU et l'heure, et le nom donne
|
---|
[3274] | 28 | Timer(const char* name=0, bool prfg=true);
|
---|
[219] | 29 |
|
---|
| 30 | // Le destructeur appelle split sans parametre.
|
---|
| 31 | virtual ~Timer();
|
---|
| 32 |
|
---|
| 33 | // Affiche le temps ecoule total/partiel, avec le nom eventuel.
|
---|
| 34 | // Si pas de parametre affiche le nom donne a la creation.
|
---|
[3274] | 35 | void Split(const char* comm=0, bool prfg=false);
|
---|
[219] | 36 |
|
---|
| 37 | // Sert a eviter que GNU ne pretende qu'on utilise pas l'objet...
|
---|
[895] | 38 | /*! To avoid not used object compiler warnings */
|
---|
[219] | 39 | void Nop() {}
|
---|
| 40 |
|
---|
[3274] | 41 | /*! \brief Return the total elapsed time (number of seconds),
|
---|
| 42 | between the object creation and the last call to Split().
|
---|
| 43 | */
|
---|
| 44 | inline int_8 TotalElapsedTime() { return elapSecT ; }
|
---|
| 45 | /*! \brief Return the partial elapsed time (number of seconds).
|
---|
| 46 | between the last two calls to Split().
|
---|
| 47 | */
|
---|
| 48 | inline int_8 PartialElapsedTime() { return elapSecP ; }
|
---|
| 49 |
|
---|
| 50 | /*! \brief Return the total CPU time in seconds,
|
---|
| 51 | between the object creation and the last call to Split().
|
---|
| 52 | */
|
---|
| 53 | inline float TotalCPUTime() { return cpuSecT; }
|
---|
| 54 | /*! \brief Return the partial CPU time in seconds,
|
---|
| 55 | between the last two calls to Split().
|
---|
| 56 | */
|
---|
| 57 | inline float PartialCPUTime() { return cpuSecP; }
|
---|
| 58 |
|
---|
[219] | 59 | private:
|
---|
| 60 | clock_t cpu0, cpuSplit;
|
---|
| 61 | time_t elapse0, elapseSplit;
|
---|
[3274] | 62 | float cpuSecT, cpuSecP; // Total and partial CPU time
|
---|
| 63 | int_8 elapSecT, elapSecP; // Total and partial elapsed time
|
---|
[895] | 64 | string timerName;
|
---|
[3274] | 65 | bool defprtflg;
|
---|
[219] | 66 | };
|
---|
| 67 |
|
---|
[895] | 68 | } // namespace SOPHYA
|
---|
| 69 |
|
---|
[3274] | 70 | #define TIMEF Timer timer(__PRETTY_FUNCTION__); timer.Nop();
|
---|
[219] | 71 |
|
---|
| 72 | #endif // CTIMER_SEEN
|
---|