00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef IXE_Timer_H
00025 #define IXE_Timer_H
00026
00027 #ifdef _WIN32
00028 # include <winsock2.h>
00029 # include "win32/timecnv.h"
00030 #else
00031 #include <sys/time.h>
00032 #endif
00033
00034 namespace IXE {
00035
00036 class Timer {
00037
00038 public:
00039 void start() { time_now(&l0); }
00040
00041 void stop() { time_now(&l1); }
00042
00043 void duration(char* buf, size_t bufSize) {
00044 long sec = l1.tv_sec - l0.tv_sec;
00045 long usec = l1.tv_usec - l0.tv_usec;
00046 if (usec < 0) {
00047 sec--;
00048 usec += 1000000;
00049 }
00050 if (sec > 60)
00051 snprintf(buf, bufSize, "%ld' %ld.%03ld sec", sec/60, sec%60, usec/1000);
00052 else if (sec > 0)
00053 snprintf(buf, bufSize, "%ld.%03ld sec", sec, usec/1000);
00054 else
00055 snprintf(buf, bufSize, "%ld.%03ld msec", usec/1000, usec%1000);
00056 }
00057
00058 struct timeval l0, l1;
00059 };
00060
00061 }
00062
00063 #endif // IXE_Timer_H