1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- #include <time.h>
- double getCurrentTimePerf(void) {
- double now;
- struct timespec ts;
- static double offset = 0;
-
-
- clock_gettime(CLOCK_MONOTONIC_RAW, &ts);
-
- now = (double)ts.tv_sec + ((double)ts.tv_nsec / 1000000000.0);
- if(offset == 0) offset = now;
-
- return now - offset;
- }
- double timeSincePerf(double past) {
- double now = getCurrentTimePerf();
- return now - past;
- }
- double getCurrentTimeEpoch(void) {
- double now;
- struct timespec ts;
-
-
- clock_gettime(CLOCK_REALTIME, &ts);
-
- now = (double)ts.tv_sec + ((double)ts.tv_nsec / 1000000000.0);
-
- return now;
- }
- double timeSinceEpoch(double past) {
- double now = getCurrentTimeEpoch();
- return now - past;
- }
|