File: timer.hc

package info (click to toggle)
craft 3.5-10
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 18,000 kB
  • ctags: 1,602
  • sloc: cpp: 3,794; makefile: 2,319; ansic: 857; sh: 385
file content (43 lines) | stat: -rw-r--r-- 806 bytes parent folder | download | duplicates (4)
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

#include "timer.h"

extern "C" {int gettimeofday (struct timeval *t, struct timezone *z);}

/*----------------------------------------------------------------------*/
/* CLASS timer (funktions)                                              */
/*----------------------------------------------------------------------*/

long sys_time ()
  {timeval  t_val;
   timezone t_zone;

   gettimeofday (&t_val, &t_zone);
   return t_val.tv_sec;
  }

void timer::delay (int dt)
  {long a;

   a = sys_time ();
   while (sys_time () - a < dt)
     {
     };

  }   

void timer::start ()
  {stamp = sys_time ();
  }

void timer::stop ()
  {dt    = (double) (sys_time () - stamp);
   stamp = sys_time ();
  }

double timer::exec ()
  {return (double) (sys_time () - stamp);
  }

double timer::read ()
  {return dt;
  }