头文件#include <time.h>

struct timeval start, end;  

gettimeofday(&start, NULL); 
/*
* to  calculate code 
*/
gettimeofday(&end, NULL);  

long long total_time = (end.tv_sec - start.tv_sec) * 1000000 + (end.tv_usec - start.tv_usec); 

// get the run time by microsecond
printf("total time is %lld us\n", total_time);

// get the run time by millisecond
total_time /= 1000; 
printf("total time is %lld ms\n", total_time)
Logo

技术共进,成长同行——讯飞AI开发者社区

更多推荐