Timer.h
1/***************************************************************************
2 * Copyright (C) 2005 by Tarek Taha *
3 * tataha@eng.uts.edu.au *
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 *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
19 ***************************************************************************/
20
21#ifndef TIMER_H_
22#define TIMER_H_
23
24#if defined WIN32
25 #include <replace.h>
26 #include <Winsock2.h> // For struct timeval
27#else
28 #include <sys/time.h>
29#endif
30#include <iostream>
31
32
34{
35 private:
36 struct timeval start_time,end_time;
37 double time_diff;
38 public:
39 MricpTimer();
40 double TimeElapsed(); // time elapsed in usec since last call
41 void Reset(); // resets timer
42 virtual ~MricpTimer();
43 /* Synchronize the loop within a period
44 * To use this u will have to initialize the timer
45 * reset the timer at the beginning of the loop
46 * and call the Synch function at the end of the loop
47 */
48 void Synch(double period); // period should be in msec
49};
50
51#endif /*TIMER_H_*/
52
Definition Timer.h:34