]> Creatis software - clitk.git/blob - common/clitkTimer.h
cosmetic for .ggo
[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://www.centreleonberard.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 //#include "clitkCommon.h"
22 #include <ctime> 
23 #if defined(unix) || defined(__APPLE__)
24 #  include <sys/time.h>
25 #  include <sys/resource.h>
26 #elif defined(_WIN32)
27 #  include <windows.h>
28 #endif
29 #include <iostream>
30 #include <utility>
31
32 namespace clitk {
33
34   class Timer {
35   public:
36     
37     //====================================================================
38     Timer();
39     void Start();
40     void Stop(bool accumulate=true);
41     void Reset();
42     void Print(std::ostream & os=std::cout) const; 
43     void Print(std::string text, std::ostream & os=std::cout) const;
44     //====================================================================
45     
46     //====================================================================
47     long double GetTimeInMicroSecond()     const { return mElapsed; }
48     long double GetMeanTimeInMicroSecond() const { return mElapsed/mNumberOfCall; }
49     long int GetNumberOfCall()             const { return mNumberOfCall; }
50     //====================================================================
51     
52   protected:
53 #if defined(unix) || defined(__APPLE__)
54     rusage mBegin; 
55     rusage mEnd;
56 #elif defined(_WIN32)
57     unsigned __int64 mBegin;
58     unsigned __int64 mEnd;
59     unsigned __int64 mFrequency;
60 #endif
61     long double mElapsed;
62     long int mNumberOfCall;
63   };
64
65 } // end namespace
66
67 // #endif
68 #endif /* end #define CLITKTIMER_H */
69