aboutsummaryrefslogtreecommitdiffstats
path: root/src/clocks.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/clocks.c')
-rw-r--r--src/clocks.c23
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 */
7double 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 */
18double wctime(void)
19{
20 struct timeval tv;
21 gettimeofday(&tv, NULL);
22 return (tv.tv_sec + 1E-6 * tv.tv_usec);
23}