用这个要比gettimeofday准确,精确到毫秒级
下面是使用timeb计算一个SQL的执行时间
#include <sys/types.h>
#include <sys/timeb.h>
#include <time.h>
struct timeb start,end;
ast_mutex_lock(&dblock);
ftime(&start);
deleteMSGResult = PQexec(conn, sqlcmd);
ftime(&end);
ast_mutex_unlock(&dblock);
unsigned long spend=0;
spend = end.millitm - start.millitm;
ast_log(LOG_NOTICE,"prepaid_staff_log: SQL spend time is %dms./n", (int)spend);