linux 应用层计算code运行时间

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 


int main() {
	
    int i;
    struct timeval startTime, endTime;
    long cost_time = 0;

    gettimeofday(&startTime, NULL);
    /*延时1s*/
    sleep(1);
    gettimeofday(&endTime, NULL);
	
    long secsDiff = endTime.tv_sec - startTime.tv_sec;
    cost_time = secsDiff * 1000000 + (endTime.tv_usec - startTime.tv_usec);
    printf(" cost_time: %ld usecs\n", cost_time);
 
    return 0;
}

 

你可能感兴趣的:(Linux,linux,gettimeofday,time)