Skip to content

Commit

Permalink
Add timespec_measure to bake.util
Browse files Browse the repository at this point in the history
  • Loading branch information
SanderMertens committed Feb 5, 2019
1 parent 36e7812 commit 24b6b95
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
9 changes: 9 additions & 0 deletions util/include/time.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,15 @@ int timespec_compare(
struct timespec t1,
struct timespec t2);

/** Measure time passed since last measurement.
*
* @param t1 Last measurement
* @result Time elapsed since last measurement
*/
UT_EXPORT
double timespec_measure(
struct timespec *t1);

/** Convert time to double-precision floating point value.
*
* @param t Time value.
Expand Down
11 changes: 11 additions & 0 deletions util/src/time.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,14 @@ char *timespec_to_str(
strftime(str, sizeof(str) - 1, "%d %m %Y %H:%M", _tm);
return ut_strdup(str);
}

double timespec_measure(
struct timespec *start)
{
struct timespec stop, temp;
timespec_gettime(&stop);
temp = stop;
stop = timespec_sub(stop, *start);
*start = temp;
return timespec_toDouble(stop);
}

0 comments on commit 24b6b95

Please sign in to comment.