#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
相关文章
- 12-21linux测耗时精确至微秒级