FOX/ObjCryst++  2022
Chronometer.h
1 /* ObjCryst++ Object-Oriented Crystallographic Library
2  (c) 2000-2007 Vincent Favre-Nicolin vincefn@users.sourceforge.net
3  2000-2001 University of Geneva (Switzerland)
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program; if not, write to the Free Software
17  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19 #ifndef __VFN_CHRONOMETER__
20 #define __VFN_CHRONOMETER__
21 
22 
23 #include <stdlib.h>
24 #include <iostream>
25 #include <boost/date_time/posix_time/posix_time_types.hpp>
26 
27 using namespace std;
28 
35 {
36  public:
37  Chronometer(){this->start();};
38  ~Chronometer(){};
39  void start() {mPaused=false;mTime0=boost::posix_time::microsec_clock::local_time();}
40  void pause() {mTime1=boost::posix_time::microsec_clock::local_time();mPaused=true;}
41  void resume()
42  {
43  mTime0=boost::posix_time::microsec_clock::local_time()-(mTime1-mTime0);
44  mPaused=false;
45  }
46  void print()
47  {
48  if(mPaused == false) mTime1=boost::posix_time::microsec_clock::local_time();
49  cout.setf(ios::fixed);
50  int tmp=cout.precision(2);
51  cout << "Elapsed time : " << this->seconds() << " s."<<endl ;
52  cout.precision(tmp);
53  cout.unsetf(ios::fixed);
54  }
55  float seconds()
56  {
57  if(mPaused ==false)
58  {
59  mTime1=boost::posix_time::microsec_clock::local_time();
60  }
61  return (mTime1-mTime0).total_microseconds()/1.0e6;
62  }
63  private:
64  bool mPaused;
65  boost::posix_time::ptime mTime0;
66  boost::posix_time::ptime mTime1;
67 };
68 
69 #endif
Simple chronometer class, with microsecond precision.
Definition: Chronometer.h:35