linux程序运行时间统计(us级别)

 

#include <stdio.h>
#include <sys/time.h>
int main()
{
  struct  timeval  start;
  struct  timeval  end;
  unsigned long timer;

  gettimeofday(&start,NULL);
  printf("hello world!\n");
  gettimeofday(&end,NULL);
  timer = 1000000 * (end.tv_sec-start.tv_sec)+ end.tv_usec-start.tv_usec;
  printf("timer = %ld us\n",timer);
  return 0;
}


你可能感兴趣的:(linux程序运行时间统计(us级别))