version 1.4, 2017/12/05 15:02:06 |
version 1.5, 2018/07/13 18:36:56 |
|
|
#include "apps.h" |
#include "apps.h" |
|
|
double |
double |
app_timer_real(int stop) |
app_timer_real(int get) |
{ |
{ |
static struct timespec start; |
static struct timespec start; |
struct timespec elapsed, now; |
struct timespec elapsed, now; |
|
|
clock_gettime(CLOCK_MONOTONIC, &now); |
clock_gettime(CLOCK_MONOTONIC, &now); |
if (stop) { |
if (get) { |
timespecsub(&now, &start, &elapsed); |
timespecsub(&now, &start, &elapsed); |
return elapsed.tv_sec + elapsed.tv_nsec / 1000000000.0; |
return elapsed.tv_sec + elapsed.tv_nsec / 1000000000.0; |
} |
} |
|
|
} |
} |
|
|
double |
double |
app_timer_user(int stop) |
app_timer_user(int get) |
{ |
{ |
static struct timeval start; |
static struct timeval start; |
struct timeval elapsed; |
struct timeval elapsed; |
struct rusage now; |
struct rusage now; |
|
|
getrusage(RUSAGE_SELF, &now); |
getrusage(RUSAGE_SELF, &now); |
if (stop) { |
if (get) { |
timersub(&now.ru_utime, &start, &elapsed); |
timersub(&now.ru_utime, &start, &elapsed); |
return elapsed.tv_sec + elapsed.tv_usec / 1000000.0; |
return elapsed.tv_sec + elapsed.tv_usec / 1000000.0; |
} |
} |