Geom Software - C++ Programming and Geometry Libraries
WOF Documentation pages v1.16
TimerC.h
1 // Copyright (C) Geom Software e.U, Bernhard Kornberger, Graz/Austria
2 //
3 // This file is part of the WOF software. WOF is commercial software.
4 // Users holding a license may use this file in accordance with the
5 // License Agreement.
6 //
7 // This software is provided AS IS with NO WARRANTY OF ANY KIND,
8 // INCLUDING THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS
9 // FOR A PARTICULAR PURPOSE.
10 //
11 // Please contact the author if any conditions of this licensing are
12 // not clear to you.
13 //
14 // Author: Bernhard Kornberger, bkorn (at) geom.at
15 // http://www.geom.at
16 
17 #pragma once
18 #include <chrono>
19 #include <string>
20 #include <iostream>
21 namespace GEOM_WOF {
22 
27 class TimerC
28 {
29 public:
34  TimerC():
35  t0(std::chrono::high_resolution_clock::now()),
36  elapsedSeconds(0.0),
37  bStopped(false)
38  {}
43  double stop()
44  {
45  bStopped=true;
46  elapsedSeconds = std::chrono::duration<double>(std::chrono::high_resolution_clock::now() - t0).count();
47  return elapsedSeconds;
48  }
55  double get() const
56  {
57  if(bStopped)
58  {
59  return elapsedSeconds;
60  }
61  else
62  {
63  return std::chrono::duration<double>(std::chrono::high_resolution_clock::now() - t0).count();
64  }
65  }
71  {
72  double elapsed(std::chrono::duration<double>(std::chrono::high_resolution_clock::now() - t0).count());
73  t0=std::chrono::high_resolution_clock::now();
74  return elapsed;
75  }
76 
82  void report(const std::string& s)
83  {
84  double elapsed(std::chrono::duration<double>(std::chrono::high_resolution_clock::now() - t0).count());
85  t0=std::chrono::high_resolution_clock::now();
86  std::cout<<"\nReport ["<<s<<"]: "<<elapsed<<" s"<<std::endl;
87  }
88 private:
89  std::chrono::high_resolution_clock::time_point t0;
90  double elapsedSeconds;
91  bool bStopped;
92 };
93 
94 
95 
96 
97 } // Namespace
Timer class.
Definition: TimerC.h:28
double stop()
Timer stop.
Definition: TimerC.h:43
double get() const
Get the elapsed time.
Definition: TimerC.h:55
void report(const std::string &s)
Report.
Definition: TimerC.h:82
TimerC()
Constructor.
Definition: TimerC.h:34
double getSecondsSinceLastReport()
Get elapsed time since last report.
Definition: TimerC.h:70
Definition: Point3.h:23