Added stop watch functions.
FossilOrigin-Name: 72930f0c2b24c2fde1e1ddaa9d7f4bb06c82539fc0820da714e93e155471e961
This commit is contained in:
parent
cd59b647cd
commit
fc6318cf8f
@ -21,6 +21,7 @@
|
|||||||
#define __CW_TIMER_H
|
#define __CW_TIMER_H
|
||||||
|
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
#include <sys/time.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @defgroup TimerFunctions Timer Functions
|
* @defgroup TimerFunctions Timer Functions
|
||||||
@ -44,14 +45,46 @@
|
|||||||
#define cw_timer_timeout(t) (time(NULL)>t ? 1 : 0)
|
#define cw_timer_timeout(t) (time(NULL)>t ? 1 : 0)
|
||||||
|
|
||||||
|
|
||||||
#define cw_clock_start()\
|
#define cw_timevaltodouble(tv) \
|
||||||
clock()
|
(( ((1000000.0)*(double)((tv)->tv_sec) + (double)(tv)->tv_usec)) )
|
||||||
|
|
||||||
#define cw_clock_stop(t)\
|
/**
|
||||||
(((double) (clock()-(t))) / CLOCKS_PER_SEC)
|
* Define a clock variable to measure runtime (not CPU runtime, but
|
||||||
|
* ralt time). This variable can be used with #cw_clock_start
|
||||||
|
* and #cw_clock_lap.
|
||||||
|
*
|
||||||
|
* @param c name of the variable
|
||||||
|
*/
|
||||||
|
#define DEFINE_CLOCK(c)\
|
||||||
|
struct timeval c;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Start the clock (stop watch), start measuring time
|
||||||
|
* @param c a pounter to a variable defined with #DEFINE_CLOCK
|
||||||
|
*/
|
||||||
|
#define cw_clock_start(c)\
|
||||||
|
gettimeofday(c,NULL);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get lap time. (stop watch)
|
||||||
|
* @param tv pointer to clock variable defined with #DEFINE_CLOCK
|
||||||
|
* @return lap time in seconds.
|
||||||
|
*/
|
||||||
|
static inline double cw_clock_lap(struct timeval *tv){
|
||||||
|
struct timeval lap;
|
||||||
|
gettimeofday(&lap,NULL);
|
||||||
|
return (cw_timevaltodouble(&lap)-cw_timevaltodouble(tv))/1000000.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An alias for #cw_clock_lap
|
||||||
|
*/
|
||||||
|
#define cw_clock_stop cw_clock_lap
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user