Commit 9f8c623b authored by Steffen Vogel's avatar Steffen Vogel 🎅🏼
Browse files

timing: add new function to compare timestamps

parent 3c1d3bc9
......@@ -32,6 +32,9 @@
extern "C" {
#endif
/** Compare two timestamps. Return zero if they are equal */
ssize_t time_cmp(const struct timespec *a, const struct timespec *b);
/** Get delta between two timespec structs */
struct timespec time_diff(const struct timespec *start, const struct timespec *end);
......
......@@ -84,3 +84,11 @@ double time_delta(const struct timespec *start, const struct timespec *end)
return time_to_double(&diff);
}
ssize_t time_cmp(const struct timespec *a, const struct timespec *b)
{
ssize_t sd = a->tv_sec - b->tv_sec;
ssize_t nsd = a->tv_nsec - b->tv_nsec;
return sd != 0 ? sd : nsd;
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment