Archived
1
0
Fork 0
This repository has been archived on 2025-09-02. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
skcblitz/timing.h
2025-09-02 14:43:36 +02:00

37 lines
732 B
C

ulong tmr_time() {
struct timespec tm;
if(clock_gettime((clockid_t)sys.tmr_timer, &tm)) {
return 0ULL;
}
return tm.tv_sec * 1000000ULL + tm.tv_nsec / 1000ULL;
}
ulong tmr_ntime() {
struct timespec tm;
if(clock_gettime((clockid_t)sys.tmr_timer, &tm)) {
return 0ULL;
}
return tm.tv_sec * 1000000000ULL + tm.tv_nsec;
}
ulong tmr_rtime() {
return tmr_time() - sys.tmr_start;
}
double tmr_ftime() {
return ((double)tmr_rtime()) / 1000000.0;
}
clockid_t tmr_gettimer() {
struct timespec tm;
clockid_t timer = CLOCK_MONOTONIC_RAW;
if(clock_gettime(timer, &tm)) {
timer = CLOCK_MONOTONIC;
if(clock_gettime(timer, &tm)) {
timer = CLOCK_REALTIME;
sys_assert(!clock_gettime(timer, &tm))
}
}
return timer;
}