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