FOX/ObjCryst++  1.10.X (development)
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 using namespace std;
27 
34 {
35  public:
36  Chronometer(){this->start();};
37  ~Chronometer(){};
38  void start() {mPaused=false;mTime0=boost::posix_time::microsec_clock::local_time();}
39  void pause() {mTime1=boost::posix_time::microsec_clock::local_time();mPaused=true;}
40  void resume()
41  {
42  mTime0=boost::posix_time::microsec_clock::local_time()-(mTime1-mTime0);
43  mPaused=false;
44  }
45  void print()
46  {
47  if(mPaused == false) mTime1=boost::posix_time::microsec_clock::local_time();
48  cout.setf(ios::fixed);
49  int tmp=cout.precision(2);
50  cout << "Elapsed time : " << this->seconds() << " s."<<endl ;
51  cout.precision(tmp);
52  cout.unsetf(ios::fixed);
53  }
54  float seconds()
55  {
56  if(mPaused ==false)
57  {
58  mTime1=boost::posix_time::microsec_clock::local_time();
59  }
60  return (mTime1-mTime0).total_microseconds()/1.0e6;
61  }
62  private:
63  bool mPaused;
64  boost::posix_time::ptime mTime0;
65  boost::posix_time::ptime mTime1;
66 };
67 
68 #endif
Simple chronometer class, with microsecond precision.
Definition: Chronometer.h:33