00001 #include <time.h> 00002 #include <sys/time.h> 00003 #include "timer.hpp" 00004 00005 00006 adr_u64 GetNow() { 00007 00008 #if HAVE_CLOCK_GETTIME 00009 // use the POSIX realtime clock to get the current time 00010 struct timespec tp; 00011 int result = clock_gettime(CLOCK_REALTIME, &tp); 00012 if (result == 0) { 00013 return adr_u64(tp.tv_sec) * 1000000 + adr_u64(tp.tv_nsec) / 1000; 00014 } 00015 #endif 00016 00017 // can't use realtime clock! Try to use gettimeofday 00018 struct timeval tv; 00019 gettimeofday(&tv, 0); 00020 return adr_u64(tv.tv_sec) * 1000000 + tv.tv_usec; 00021 }