| 40 | |
| 41 | static double t0 = 0; |
| 42 | double __hxcpp_time_stamp() |
| 43 | { |
| 44 | #ifdef HX_WINDOWS |
| 45 | static __int64 t0=0; |
| 46 | static double period=0; |
| 47 | __int64 now; |
| 48 | |
| 49 | if (QueryPerformanceCounter((LARGE_INTEGER*)&now)) |
| 50 | { |
| 51 | if (t0==0) |
| 52 | { |
| 53 | t0 = now; |
| 54 | __int64 freq; |
| 55 | QueryPerformanceFrequency((LARGE_INTEGER*)&freq); |
| 56 | if (freq!=0) |
| 57 | period = 1.0/freq; |
| 58 | } |
| 59 | if (period!=0) |
| 60 | return (now-t0)*period; |
| 61 | } |
| 62 | |
| 63 | return (double)clock() / ( (double)CLOCKS_PER_SEC); |
| 64 | #elif defined(HX_MACOS) |
| 65 | static double time_scale = 0.0; |
| 66 | if (time_scale==0.0) |
| 67 | { |
| 68 | mach_timebase_info_data_t info; |
| 69 | mach_timebase_info(&info); |
| 70 | time_scale = 1e-9 * (double)info.numer / info.denom; |
| 71 | } |
| 72 | double r = mach_absolute_time() * time_scale; |
| 73 | return mach_absolute_time() * time_scale; |
| 74 | #else |
| 75 | #if defined(IPHONE) || defined(APPLETV) |
| 76 | double t = CACurrentMediaTime(); |
| 77 | #elif defined(USE_GETTIMEOFDAY) |
| 78 | struct timeval tv; |
| 79 | if( gettimeofday(&tv,NULL) ) |
| 80 | return 0; |
| 81 | double t = ( tv.tv_sec + ((double)tv.tv_usec) / 1000000.0 ); |
| 82 | #elif defined(USE_CLOCK_GETTIME) |
| 83 | struct timespec ts; |
| 84 | clock_gettime(CLOCK_MONOTONIC, &ts); |
| 85 | double t = ( ts.tv_sec + ((double)ts.tv_nsec)*1e-9 ); |
| 86 | #else |
| 87 | double t = (double)clock() * (1.0 / CLOCKS_PER_SEC); |
| 88 | #endif |
| 89 | if (t0==0) t0 = t; |
| 90 | return t-t0; |
| 91 | #endif |
| 92 | } |
| 93 | |
| 94 | /* |
| 95 | * for the provided Epoch time, fills the passed struct tm with date_time representation in local time zone |
no outgoing calls
no test coverage detected