File: util_timer.cpp

package info (click to toggle)
mercator 0.3.0-2
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 2,008 kB
  • sloc: sh: 10,433; cpp: 4,482; makefile: 115
file content (46 lines) | stat: -rw-r--r-- 996 bytes parent folder | download | duplicates (8)
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
40
41
42
43
44
45
46
// This file may be redistributed and modified only under the terms of
// the GNU General Public License (See COPYING for details).
// Copyright (C) 2002 Jari Sundell

#include "util_timer.h"

namespace Util {

Timer::Timer() {
  gettimeofday(&m_start,0);
}

void Timer::start() {
  gettimeofday(&m_start,0);
}

void Timer::stop() {
  gettimeofday(&m_stop,0);    
}

double Timer::interval() {
  struct timeval time;
  double inter;
  gettimeofday(&time,0);
  inter=(time.tv_sec-m_start.tv_sec)+((double)(time.tv_usec-m_start.tv_usec))/1000000.0;
  gettimeofday(&m_start,0);
  return inter;

}

double Timer::time() {
  return (m_stop.tv_sec-m_start.tv_sec)+((double)(m_stop.tv_usec-m_start.tv_usec))/1000000.0;
}

double Timer::now() {
  gettimeofday(&m_temp,0);
  return (double)(m_temp.tv_sec-m_start.tv_sec)+(double)(m_temp.tv_usec-m_start.tv_usec)/1000000.0;
}

double Timer::real() {
  struct timeval t;
  gettimeofday(&t,0);
  return (double)t.tv_sec + (double)t.tv_usec / 1000000.0;
}

}