24 lines
529 B
C
24 lines
529 B
C
#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);
|
|
}
|