clockTime.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Class
25  Foam::clockTime
26 
27 Description
28  Starts timing (using rtc) and returns elapsed time from start.
29  Better resolution (2uSec instead of ~20mSec) than cpuTime.
30 
31 SourceFiles
32  clockTime.C
33 
34 \*---------------------------------------------------------------------------*/
35 
36 #ifndef clockTime_H
37 #define clockTime_H
38 
39 #include <sys/types.h>
40 
41 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
42 
43 namespace Foam
44 {
45 
46 /*---------------------------------------------------------------------------*\
47  Class clockTime Declaration
48 \*---------------------------------------------------------------------------*/
49 
50 class clockTime
51 {
52  // Private Data
53 
54  //- Time structure used
55  typedef struct timeval timeType;
56 
57  timeType startTime_;
58 
59  mutable timeType lastTime_;
60  mutable timeType newTime_;
61 
62  // Private Member Functions
63 
64  //- Retrieve the current time values from the system
65  static void getTime(timeType&);
66 
67  //- Difference between two times
68  static double timeDifference(const timeType& beg, const timeType& end);
69 
70 
71 public:
72 
73  // Constructors
74 
75  //- Construct with the current clock time
76  clockTime();
77 
78 
79  // Member Functions
80 
81  //- Return time (in seconds) from the start
82  double elapsedTime() const;
83 
84  //- Return time (in seconds) since last call to timeIncrement()
85  double timeIncrement() const;
86 };
87 
88 
89 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
90 
91 } // End namespace Foam
92 
93 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
94 
95 #endif
96 
97 // ************************************************************************* //
double elapsedTime() const
Return time (in seconds) from the start.
Definition: clockTime.C:55
clockTime()
Construct with the current clock time.
Definition: clockTime.C:45
double timeIncrement() const
Return time (in seconds) since last call to timeIncrement()
Definition: clockTime.C:62
Namespace for OpenFOAM.
Starts timing (using rtc) and returns elapsed time from start. Better resolution (2uSec instead of ~2...
Definition: clockTime.H:49