mirror of
https://github.com/pumpitupdev/pumptools.git
synced 2024-11-28 00:20:47 +01:00
util/time: Add functions to measure time with high precision
This commit is contained in:
parent
1ab724eb45
commit
d9a96a818e
@ -66,4 +66,38 @@ void util_time_get_current_time(struct util_time_timestamp* timestamp)
|
||||
timestamp->month = tm->tm_mon + 1;
|
||||
// Years since 1900
|
||||
timestamp->year = tm->tm_year + 1900;
|
||||
}
|
||||
|
||||
util_time_counter_t util_time_get_counter()
|
||||
{
|
||||
struct timespec tspec;
|
||||
|
||||
clock_gettime(CLOCK_MONOTONIC, &tspec);
|
||||
|
||||
return tspec.tv_sec * 1000 * 1000 * 1000 + tspec.tv_nsec;
|
||||
}
|
||||
|
||||
uint64_t util_time_get_elapsed_ns(util_time_counter_t counter_delta)
|
||||
{
|
||||
return counter_delta;
|
||||
}
|
||||
|
||||
uint64_t util_time_get_elapsed_us(util_time_counter_t counter_delta)
|
||||
{
|
||||
return counter_delta / 1000;
|
||||
}
|
||||
|
||||
double util_time_get_elapsed_us_double(util_time_counter_t counter_delta)
|
||||
{
|
||||
return ((double) counter_delta) / 1000.0;
|
||||
}
|
||||
|
||||
uint32_t util_time_get_elapsed_ms(util_time_counter_t counter_delta)
|
||||
{
|
||||
return counter_delta / 1000 / 1000;
|
||||
}
|
||||
|
||||
double util_time_get_elapsed_ms_double(util_time_counter_t counter_delta)
|
||||
{
|
||||
return ((double) counter_delta) / 1000.0 / 1000.0;
|
||||
}
|
@ -13,6 +13,8 @@ struct util_time_timestamp {
|
||||
uint16_t millisec;
|
||||
};
|
||||
|
||||
typedef uint64_t util_time_counter_t;
|
||||
|
||||
void util_time_sleep_ns(uint64_t time_ns);
|
||||
|
||||
void util_time_sleep_us(uint64_t time_us);
|
||||
@ -23,4 +25,16 @@ void util_time_sleep_sec(uint64_t time_sec);
|
||||
|
||||
void util_time_get_current_time(struct util_time_timestamp* timestamp);
|
||||
|
||||
util_time_counter_t util_time_get_counter();
|
||||
|
||||
uint64_t util_time_get_elapsed_ns(util_time_counter_t counter_delta);
|
||||
|
||||
uint64_t util_time_get_elapsed_us(util_time_counter_t counter_delta);
|
||||
|
||||
double util_time_get_elapsed_us_double(util_time_counter_t counter_delta);
|
||||
|
||||
uint32_t util_time_get_elapsed_ms(util_time_counter_t counter_delta);
|
||||
|
||||
double util_time_get_elapsed_ms_double(util_time_counter_t counter_delta);
|
||||
|
||||
#endif //UTIL_TIME_H
|
||||
|
Loading…
Reference in New Issue
Block a user