22 #include <sys/types.h>
34 void start() {clock_gettime(CLOCK_PROCESS_CPUTIME_ID,&tv1);}
35 void stop() {clock_gettime(CLOCK_PROCESS_CPUTIME_ID,&tv2);}
37 double time() {
return(
double(tv2.tv_sec - tv1.tv_sec) +
double(tv2.tv_nsec - tv1.tv_nsec) * 1.0E-9);}
38 double timeMSec() {
return(time() * 1.0E3);}
39 double timeUSec() {
return(time() * 1.0E6);}
43 clock_gettime(CLOCK_PROCESS_CPUTIME_ID,&tv2);
50 clock_gettime(CLOCK_PROCESS_CPUTIME_ID,&tmp);
51 return(
double(tmp.tv_sec - tv1.tv_sec) +
double(tmp.tv_nsec - tv1.tv_nsec) * 1.0E-9);
65 void start() {clock_gettime(CLOCK_PROCESS_CPUTIME_ID,&tv1);}
68 clock_gettime(CLOCK_PROCESS_CPUTIME_ID,&tv2);
71 double getTotal() {
return total;}
73 double time() {
return(
double(tv2.tv_sec - tv1.tv_sec) +
double(tv2.tv_nsec - tv1.tv_nsec) * 1.0E-9);}
74 double timeMSec() {
return(time() * 1.0E3);}
75 double timeUSec() {
return(time() * 1.0E6);}
79 clock_gettime(CLOCK_PROCESS_CPUTIME_ID,&tv2);
86 clock_gettime(CLOCK_PROCESS_CPUTIME_ID,&tmp);
87 return(
double(tmp.tv_sec - tv1.tv_sec) +
double(tmp.tv_nsec - tv1.tv_nsec) * 1.0E-9);
91 inline unsigned GetTimeUSec()
94 struct SystemTime time;
96 return(time.seconds*1000000 + time.useconds);
99 clock_gettime(CLOCK_REALTIME,&ts);
100 return(
double(ts.tv_sec)*1000000.0 +
double(ts.tv_nsec)*(1.0E-3));
104 inline double GetTimeSec()
107 struct SystemTime time;
108 GetSystemTime(&time);
109 return((
double)time.seconds + time.useconds*(1.0E-6));
112 clock_gettime(CLOCK_REALTIME,&ts);
113 return(
double(ts.tv_sec) +
double(ts.tv_nsec)*(1.0E-9));
117 inline double GetProcessTimeSec()
120 clock_gettime(CLOCK_PROCESS_CPUTIME_ID,&ts);
121 return(
double(ts.tv_sec) +
double(ts.tv_nsec)*(1.0E-9));
124 inline void GetDate(
struct tm &date)
126 time_t t = time(NULL);
127 localtime_r(&t,&date);
130 inline void Sleep(
double sec)
132 usleep((
int)(sec * 1E6));
137 double tStart, lapStart, tStop;
139 double getTickCount()
142 clock_gettime(CLOCK_PROCESS_CPUTIME_ID,&ts);
143 return(
double(ts.tv_sec) +
double(ts.tv_nsec)*(1.0E-9));
147 {fname=_fname; tStart = lapStart = getTickCount(); lapNum = 0; tStop=0.0;}
148 void Lap(
int lineNum)
149 {tStop=getTickCount(); printf(
"%s line %d lap %d: %9.3fus\n",fname,lineNum,lapNum,(tStop-lapStart)*1e6); lapNum++; lapStart=tStop;}
151 {tStop=getTickCount(); printf(
"%s: %0.6fms\n",fname,(tStop-tStart)*1000.0);}