aboutsummaryrefslogtreecommitdiff
path: root/src/Timer.hh
blob: e801cf34556fa030d7c7af5076980ab454f227e3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#ifndef __TIMER_HH_
#define __TIMER_HH_
#include <stdio.h>
#include <sys/types.h>
#include <sys/times.h>
#include <sys/time.h>

class Timer {
  int running;
  double treal,tuser,tsystem;
  tms tm;
  timeval tv;
public:
  Timer() { reset(); }
  void reset(){
    treal=tuser=tsystem=0;
    running=0;
  }
  int start();
  int stop();
  void elapsedTimeSeconds(double &system,double &user,double &real);
  void elapsedTimeSeconds(float &system,float &user,float &real){
    double s,u,r;
    elapsedTimeSeconds(s,u,r);
    system=s; user=u; real=r;
  }
  void print(char *preface="",FILE *f=stdout);
};

class Counter {
	int count;
public:
	Counter():count(0){}
	void reset() {count = 0;}
	int incr(){ return count++;}
	int nCount() { return count;}
};

#endif