MCPcopy Create free account
hub / github.com/HaxeFoundation/hxcpp / __hxcpp_time_stamp

Function __hxcpp_time_stamp

src/hx/Date.cpp:42–92  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

40
41static double t0 = 0;
42double __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

Callers 7

GCStartMethod · 0.85
GCEndMethod · 0.85
HXTAfterMarkMethod · 0.85
Immix.cppFile · 0.85
ProfileCollectSummaryMethod · 0.85
addTimeMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected