]> Creatis software - clitk.git/blob - common/clitkTimer.h
added the new headers
[clitk.git] / common / clitkTimer.h
1 /*=========================================================================
2   Program:   vv                     http://www.creatis.insa-lyon.fr/rio/vv
3
4   Authors belong to: 
5   - University of LYON              http://www.universite-lyon.fr/
6   - Léon Bérard cancer center       http://oncora1.lyon.fnclcc.fr
7   - CREATIS CNRS laboratory         http://www.creatis.insa-lyon.fr
8
9   This software is distributed WITHOUT ANY WARRANTY; without even
10   the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11   PURPOSE.  See the copyright notices for more information.
12
13   It is distributed under dual licence
14
15   - BSD        See included LICENSE.txt file
16   - CeCILL-B   http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
17 ======================================================================-====*/
18 #ifndef CLITKTIMER_H
19 #define CLITKTIMER_H
20 /**
21    ===================================================================
22    * @file   clitkTimer.h
23    * @author David Sarrut <David.Sarrut@creatis.insa-lyon.fr>
24    * @date   18 Jul 2007 16:26:08
25
26    * @brief  
27
28    ===================================================================*/
29
30 #include "clitkCommon.h"
31 #include <ctime> 
32 #if defined(unix)
33 #  include <sys/time.h>
34 #  include <sys/resource.h>
35 #elif defined(WIN32)
36 #  include <windows.h>
37 #endif
38 #include <iostream>
39 #include <utility>
40
41 namespace clitk {
42
43   class Timer {
44   public:
45     
46     //====================================================================
47     Timer();
48     void Start();
49     void Stop(bool accumulate=true);
50     void Reset();
51     void Print(std::ostream & os=std::cout) const; 
52     void Print(std::string text, std::ostream & os=std::cout) const;
53     //====================================================================
54     
55     //====================================================================
56     long double GetTimeInMicroSecond()     const { return mElapsed; }
57     long double GetMeanTimeInMicroSecond() const { return mElapsed/mNumberOfCall; }
58     long int GetNumberOfCall()             const { return mNumberOfCall; }
59     //====================================================================
60     
61   protected:
62 #if defined(unix)
63     rusage mBegin; 
64     rusage mEnd;
65 #elif defined(WIN32)
66     unsigned __int64 mBegin;
67     unsigned __int64 mEnd;
68     unsigned __int64 mFrequency;
69 #endif
70     long double mElapsed;
71     long int mNumberOfCall;
72   };
73
74 } // end namespace
75
76 // #endif
77 #endif /* end #define CLITKTIMER_H */
78