OpenVDB  3.0.0
CpuTimer.h
Go to the documentation of this file.
1 //
3 // Copyright (c) 2012-2014 DreamWorks Animation LLC
4 //
5 // All rights reserved. This software is distributed under the
6 // Mozilla Public License 2.0 ( http://www.mozilla.org/MPL/2.0/ )
7 //
8 // Redistributions of source code must retain the above copyright
9 // and license notice and the following restrictions and disclaimer.
10 //
11 // * Neither the name of DreamWorks Animation nor the names of
12 // its contributors may be used to endorse or promote products derived
13 // from this software without specific prior written permission.
14 //
15 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY INDIRECT, INCIDENTAL,
20 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 // IN NO EVENT SHALL THE COPYRIGHT HOLDERS' AND CONTRIBUTORS' AGGREGATE
27 // LIABILITY FOR ALL CLAIMS REGARDLESS OF THEIR BASIS EXCEED US$250.00.
28 //
30 
31 #ifndef OPENVDB_UTIL_CPUTIMER_HAS_BEEN_INCLUDED
32 #define OPENVDB_UTIL_CPUTIMER_HAS_BEEN_INCLUDED
33 
34 #include <string>
35 #include <tbb/tick_count.h>
36 #include <sstream>
37 
38 namespace openvdb {
40 namespace OPENVDB_VERSION_NAME {
41 namespace util {
42 
50 class CpuTimer
51 {
52 public:
53 
55  CpuTimer() : mT0(tbb::tick_count::now()) {}
56 
59  inline void start() { mT0 = tbb::tick_count::now(); }
60 
63  inline void start(const std::string& msg)
64  {
65  std::cerr << msg << " ... ";
66  this->start();
67  }
68 
71  inline void restart(const std::string& msg)
72  {
73  this->stop();
74  this->start(msg);
75  }
76 
78  inline double delta() const
79  {
80  tbb::tick_count::interval_t dt = tbb::tick_count::now() - mT0;
81  return 1000.0*dt.seconds();
82  }
83 
85  inline void stop() const
86  {
87  const double t = this->delta();
88  std::ostringstream ostr;
89  ostr << "completed in " << std::setprecision(3) << t << " ms\n";
90  std::cerr << ostr.str();
91  }
92 
93 private:
94 
95  tbb::tick_count mT0;
96 };// CpuTimer
97 
98 } // namespace util
99 } // namespace OPENVDB_VERSION_NAME
100 } // namespace openvdb
101 
102 
103 #endif // OPENVDB_UTIL_CPUTIMER_HAS_BEEN_INCLUDED
104 
105 // Copyright (c) 2012-2014 DreamWorks Animation LLC
106 // All rights reserved. This software is distributed under the
107 // Mozilla Public License 2.0 ( http://www.mozilla.org/MPL/2.0/ )
Simple timer for basic profiling.
Definition: CpuTimer.h:50
double delta() const
Return Time diference in milliseconds since construction or start was called.
Definition: CpuTimer.h:78
void start(const std::string &msg)
Print message and re-start timer.
Definition: CpuTimer.h:63
void stop() const
Prints time in milliseconds since construction or start was called.
Definition: CpuTimer.h:85
#define OPENVDB_VERSION_NAME
Definition: version.h:43
Definition: Exceptions.h:39
void start()
Restart timer.
Definition: CpuTimer.h:59
CpuTimer()
Initiate timer.
Definition: CpuTimer.h:55
Definition: Coord.h:38
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:71
void restart(const std::string &msg)
Stops previous timer, print message and re-start timer.
Definition: CpuTimer.h:71