linux测耗时精确至微秒级
#include <stdio.h>
#include <string.h>
#include <sys/time.h>
#include <unistd.h>
int main(int argc, char **argv)
{
struct timeval dwStart;
struct timeval dwEnd;
float dwTime = 0;
gettimeofday(&dwStart, NULL);
sleep(2);
gettimeofday(&dwEnd, NULL);
dwTime = 1000000 * (dwEnd.tv_sec - dwStart.tv_sec) + (dwEnd.tv_usec - dwStart.tv_usec);
dwTime = dwTime / 1000000;
printf("log --> %fs\n", dwTime);
return 0;
}
--------------------------------------------------------------
output:
log --> 2.000512s