summaryrefslogtreecommitdiffstats
path: root/WDL/time_precise.h
blob: c4ed52cdaa2269c63987e554a8a3de855bc3f195 (plain) (blame)
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
#ifndef _WDL_TIME_PRECISE_H_
#define _WDL_TIME_PRECISE_H_

#ifdef _WIN32
#include <windows.h>
#elif defined(__APPLE__)
#include <sys/time.h>
#else
#include <time.h>
#endif

#include "wdltypes.h"


#ifdef WDL_TIME_PRECISE_DECL
WDL_TIME_PRECISE_DECL
#else
static WDL_STATICFUNC_UNUSED
#endif

double time_precise()
{
#ifdef _WIN32
  LARGE_INTEGER freq;
  QueryPerformanceFrequency(&freq);

  LARGE_INTEGER now;
  QueryPerformanceCounter(&now);
  return (double)now.QuadPart / (double)freq.QuadPart;
#elif defined(__APPLE__)
  struct timeval tm={0,};
  gettimeofday(&tm,NULL);
  return (double)tm.tv_sec + (double)tm.tv_usec/1000000;
#else
  struct timespec tm={0,};
  clock_gettime(CLOCK_MONOTONIC,&tm);
  return (double)tm.tv_sec + (double)tm.tv_nsec/1000000000;
#endif
}

#endif