cpuTimeCxx.H
Go to the documentation of this file.
1/*---------------------------------------------------------------------------*\
2 ========= |
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4 \\ / O peration |
5 \\ / A nd | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2018-2019 OpenCFD Ltd.
9-------------------------------------------------------------------------------
10License
11 This file is part of OpenFOAM.
12
13 OpenFOAM is free software: you can redistribute it and/or modify it
14 under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
17
18 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25
26Class
27 Foam::cpuTimeCxx
28
29Description
30 Starts timing CPU usage and return elapsed time from start.
31
32See also
33 clockTime
34
35SourceFiles
36 cpuTimeCxx.C
37
38\*---------------------------------------------------------------------------*/
39
40#ifndef cpuTimeCxx_H
41#define cpuTimeCxx_H
42
43#include <ctime>
44
45// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46
47namespace Foam
48{
49
50/*---------------------------------------------------------------------------*\
51 Class cpuTimeCxx Declaration
52\*---------------------------------------------------------------------------*/
54class cpuTimeCxx
55{
56 //- Time structure used, with additional methods
57 struct value_type
58 {
59 std::clock_t value;
60
61 //- Construct with the current clock time
62 value_type();
63
64 //- Update with the current clock time
65 void update();
66 };
67
68
69 // Private Data
70
71 //- Start time, at the time of construction
72 value_type start_;
73
74 //- Last time when elapsedTime or timeIncrement was called
75 mutable value_type last_;
76
77
78 // Private Member Functions
79
80 //- Difference between two times (a - b)
81 static inline double diff(const value_type& a, const value_type& b);
82
83
84public:
85
86 // Constructors
87
88 //- Construct with the current clock time
89 cpuTimeCxx();
90
91
92 // Member Functions
93
94 //- Reset to use the current time for the start time
95 void resetCpuTime();
96
97 //- Return CPU time (in seconds) from the start
98 double elapsedCpuTime() const;
99
100 //- Return CPU time (in seconds) since last call to cpuTimeIncrement()
101 double cpuTimeIncrement() const;
102};
103
104
105// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
106
107} // End namespace Foam
108
109// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
110
111#endif
112
113// ************************************************************************* //
Starts timing CPU usage and return elapsed time from start.
Definition: cpuTimeCxx.H:54
void resetCpuTime()
Reset to use the current time for the start time.
Definition: cpuTimeCxx.C:61
cpuTimeCxx()
Construct with the current clock time.
Definition: cpuTimeCxx.C:46
double cpuTimeIncrement() const
Return CPU time (in seconds) since last call to cpuTimeIncrement()
Definition: cpuTimeCxx.C:75
double elapsedCpuTime() const
Return CPU time (in seconds) from the start.
Definition: cpuTimeCxx.C:68
mesh update()
Namespace for OpenFOAM.
volScalarField & b
Definition: createFields.H:27