ExternalTiming.h
1 // ExternalTiming by Dave Kish 2013
2 // This is an externally usable implementation of some timing functions for use with outside libraries and projects
3 // and maintains our ability to work on Windows, Linux and PS3
4 #pragma once
5 #ifndef EXTERNAL_TIMING_H
6 #define EXTERNAL_TIMING_H
7 
8 #if defined(WIN32)
9  #include "windows.h"
10 #else
11  #include <sys/time.h>
12 #endif
13 
14 namespace ExternalTiming
15 {
16 #ifdef WIN32
17  static unsigned int ExternalGetTickCount()
18  {
19  return GetTickCount();
20  }
21 #else
22  static unsigned int ExternalGetTickCount()
23  {
24  struct timespec now;
25  if (gettimeofday(&now, NULL) != 0)
26  {
27  return 0;
28  }
29 
30  return (unsigned int)((now.tv_sec * 1000) + (now.tv_usec / 1000));
31  }
32 #endif
33 
34 } // end of ExternalTiming namespace
35 
36 #endif // EXTERNAL_TIMING_H