00001 #ifndef __TIMER_H__ 00002 #define __TIMER_H__ 00003 00004 #include <time.h> 00005 00006 // start timer and return start time 00007 double start_time() { 00008 struct timespec tp; 00009 clock_gettime(CLOCK_REALTIME, &tp); 00010 return 1e9*tp.tv_sec + tp.tv_nsec; 00011 } 00012 00013 // return time in seconds 00014 double stop_time(double begin) { 00015 struct timespec tp; 00016 clock_gettime(CLOCK_REALTIME, &tp); 00017 double end = 1e9*tp.tv_sec + tp.tv_nsec; 00018 return (end-begin)*1e-9; 00019 } 00020 00021 #endif // __TIMER_H__