FloatImg/lib/fimg-timers.c

48 lines
1.0 KiB
C
Raw Normal View History

2019-03-04 02:22:55 +11:00
/*
2021-03-18 04:32:51 +11:00
* timers.c BUGS INSIDE ?
2019-03-04 02:22:55 +11:00
*/
#include <stdio.h>
#include <sys/time.h>
extern int verbosity;
/* ----------------------------------------------------------------- */
static double dtime(void)
{
struct timeval t;
double d;
(void)gettimeofday(&t, NULL);
d = (double)t.tv_sec + (double)t.tv_usec / 1e6;
return d;
}
/* ----------------------------------------------------------------- */
2019-05-28 21:03:08 +11:00
/* we can have only one timer at this time. patches welcome.*/
2019-03-04 02:22:55 +11:00
static double memory_time;
double fimg_timer_set(int whot)
{
double current;
2022-07-06 19:27:55 +11:00
if (whot) fprintf(stderr, "in %s whot is %d\n", __func__, whot);
2019-03-04 02:22:55 +11:00
current = dtime();
#if DEBUG_LEVEL
fprintf(stderr, "%s ( %d ) -> current %f\n", __func__, whot, current);
#endif
memory_time = current;
return memory_time;
}
/* ----------------------------------------------------------------- */
double fimg_timer_get(int whot)
{
double current;
2022-07-06 19:27:55 +11:00
if (whot) fprintf(stderr, "in %s whot is %d\n", __func__, whot);
2019-03-04 02:22:55 +11:00
current = dtime();
return current - memory_time;
}
/* ----------------------------------------------------------------- */