This repository has been archived on 2022-10-18. You can view files and clone it, but cannot push or open issues or pull requests.
HPC/Project2/Project2-code/hist/walltime.h

25 lines
529 B
C
Raw Permalink Normal View History

2022-10-18 12:39:50 +00:00
#ifdef GETTIMEOFDAY
#include <sys/time.h> // For struct timeval, gettimeofday
#else
#include <time.h> // For struct timespec, clock_gettime, CLOCK_MONOTONIC
#endif
#include <stdio.h>
#include <stdlib.h>
double wall_time() {
#ifdef GETTIMEOFDAY
struct timeval t;
gettimeofday(&t, NULL);
return 1. * t.tv_sec + 1.e-6 * t.tv_usec;
#else
struct timespec t;
clock_gettime(CLOCK_MONOTONIC, &t);
return 1. * t.tv_sec + 1.e-9 * t.tv_nsec;
#endif
}
void die(const char *message) {
perror(message);
exit(EXIT_FAILURE);
}