diff options
| author | Bjoern B. Brandenburg <bbb@cs.unc.edu> | 2011-01-30 12:18:26 -0500 |
|---|---|---|
| committer | Bjoern B. Brandenburg <bbb@cs.unc.edu> | 2011-02-03 17:40:16 -0500 |
| commit | 86b445e39c3c7eed076b01795b17f34481517288 (patch) | |
| tree | 88db1c398fde6882328bcba74fb49945fa4bce24 /src | |
| parent | 46f3b11a1f49d49120415b56b6f627c66e4b4d1b (diff) | |
Export wctime() and cputime() from rtspin to library clients
The timing functions are quite handy when building benchmark tasks.
Avoid copy&paste reuse by making them available via the library.
Diffstat (limited to 'src')
| -rw-r--r-- | src/clocks.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/clocks.c b/src/clocks.c new file mode 100644 index 0000000..fcb94e5 --- /dev/null +++ b/src/clocks.c | |||
| @@ -0,0 +1,23 @@ | |||
| 1 | #include <stdio.h> | ||
| 2 | |||
| 3 | #include <sys/time.h> | ||
| 4 | #include <time.h> | ||
| 5 | |||
| 6 | /* CPU time consumed so far in seconds */ | ||
| 7 | double cputime(void) | ||
| 8 | { | ||
| 9 | struct timespec ts; | ||
| 10 | int err; | ||
| 11 | err = clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ts); | ||
| 12 | if (err != 0) | ||
| 13 | perror("clock_gettime"); | ||
| 14 | return (ts.tv_sec + 1E-9 * ts.tv_nsec); | ||
| 15 | } | ||
| 16 | |||
| 17 | /* wall-clock time in seconds */ | ||
| 18 | double wctime(void) | ||
| 19 | { | ||
| 20 | struct timeval tv; | ||
| 21 | gettimeofday(&tv, NULL); | ||
| 22 | return (tv.tv_sec + 1E-6 * tv.tv_usec); | ||
| 23 | } | ||
