File: timer.cpp

package info (click to toggle)
muparserx 4.0.12-2.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,240 kB
  • sloc: cpp: 10,953; ansic: 28; makefile: 8
file content (51 lines) | stat: -rw-r--r-- 1,028 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
44
45
46
47
48
49
50
51
#include "timer.h"

#include <stdio.h>
#include <time.h>

#if defined(__WIN32__) || defined(_WIN32)
#include <Windows.h>
DWORD tvs, tve;
#else
#include <sys/time.h>
struct timeval	tvs, tve;
#endif


void StartTimer(void)
{
#if defined(__WIN32__) || defined(_WIN32)
  tvs = GetTickCount();
#else
  if (gettimeofday(&tvs,0)) fprintf(stderr,"cant get time!\n");
#endif
}

double StopTimer(void)
{
#if defined(__WIN32__) || defined(_WIN32)
  tve = GetTickCount();
  return tve - tvs;
#else
  if (gettimeofday(&tve,0)) fprintf(stderr,"cant get time!\n");
  return 1000 * (tve.tv_sec - tvs.tv_sec + (double)(tve.tv_usec - tvs.tv_usec) / 1000000.0);
#endif
}

double PrintTimer(void)
{
  double t;

#if defined(__WIN32__) || defined(_WIN32)
  tve = GetTickCount();
  t = (double)(tve - tvs) / 1000.0;
  printf("%.3f ",t);
  return t;
#else
  if (gettimeofday(&tve,0)) fprintf(stderr,"cant get time!\n");
  t = 1000 * (tve.tv_sec - tvs.tv_sec + (double)(tve.tv_usec - tvs.tv_usec)/1000000.0);
  printf("%.3f ",t);
  return t;
#endif
}