Geom Software - C++ Programming and Geometry Libraries
WOF Documentation pages v1.11
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  void report(const std::string& s)
72  {
73  double elapsed(std::chrono::duration<double>(std::chrono::high_resolution_clock::now() - t0).count());
74  t0=std::chrono::high_resolution_clock::now();
75  std::cout<<"\nReport ["<<s<<"]: "<<elapsed<<" s"<<std::endl;
76  }
77 private:
78  std::chrono::high_resolution_clock::time_point t0;
79  double elapsedSeconds;
80  bool bStopped;
81 };
82 
83 
84 
85 
86 } // 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:71
TimerC()
Constructor.
Definition: TimerC.h:34
Definition: Point3.h:23