GeoTessCPP: include/CpuTimer.h Source File

GeoTessCPP 2.0.0 Software to facilitate storage and retrieval of 3D information about the Earth.

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Friends Macros
CpuTimer.h
Go to the documentation of this file.
1 //- ****************************************************************************
2 //-
3 //- Copyright 2009 Sandia Corporation. Under the terms of Contract
4 //- DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government
5 //- retains certain rights in this software.
6 //-
7 //- BSD Open Source License.
8 //- All rights reserved.
9 //-
10 //- Redistribution and use in source and binary forms, with or without
11 //- modification, are permitted provided that the following conditions are met:
12 //-
13 //- * Redistributions of source code must retain the above copyright notice,
14 //- this list of conditions and the following disclaimer.
15 //- * Redistributions in binary form must reproduce the above copyright
16 //- notice, this list of conditions and the following disclaimer in the
17 //- documentation and/or other materials provided with the distribution.
18 //- * Neither the name of Sandia National Laboratories nor the names of its
19 //- contributors may be used to endorse or promote products derived from
20 //- this software without specific prior written permission.
21 //-
22 //- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23 //- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 //- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 //- ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
26 //- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 //- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 //- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29 //- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30 //- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 //- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 //- POSSIBILITY OF SUCH DAMAGE.
33 //-
34 //- ****************************************************************************
35
36 #ifndef CPU_TIMER_H
37 #define CPU_TIMER_H
38
39 // **** _SYSTEM INCLUDES_ ******************************************************
40
41 #include <ctime>
42
43 // use standard library objects
44 using namespace std;
45
46 // **** _LOCAL INCLUDES_ *******************************************************
47
48 #include "CPPUtils.h"
49
50 // **** _BEGIN GEOTESS NAMESPACE_ **********************************************
51
52 namespace geotess {
53
54 // **** _FORWARD REFERENCES_ ***************************************************
55
56 // **** _CLASS DEFINITION_ *****************************************************
57
64 class GEOTESS_EXP_IMP CpuTimer
65 {
66 private:
67
68 // Last real time set when init_timer was called or 'this' CpuTimer was
69 // constructed (msec)
70 double cpuRealTime;
71
72 // Last cpu time set when init_timer was called or 'this' CpuTimer was
73 // constructed (msec)
74 double cpuCPUTime;
75
76 public:
77
78 // Default constructor initialies timer
79 CpuTimer();
80
81 // Initializes timer
82 void initTimer();
83
87 static double getCurrCPUTime()
88 { return (double) 1000.0 * clock() / CLOCKS_PER_SEC; }
89
93 static double getCurrRealTime()
94 { return (double) 1000.0 * time(NULL); }
95
96 // Returns cpu time (ms) since last init_timer call. The second
97 // function also reinitializes cpuCPUTime.
98 double cpuTime();
99 double cpuTimeInit();
100
101 // Returns real time (ms) since last init_timer call. The second
102 // function also reinitializes cpuRealTime.
103 double realTime();
104 double realTimeInit();
105
106 // Static elapsed time string output functions given an input elapsed
107 // time in msec.
108 static string elapsedTimeString(double tm);
109 static string elapsedTimeStringFraction(double tm);
110 static string elapsedTimeStringFractionAbbrvUnits(double tm);
111
112 // Returns the current time string
113 static string now();
114 };
115
116 } // end namespace geotess
117
118 #endif // CPU_TIMER_H