ARTS-S c语言统计程序运行时间

#include <stdio.h>
#include <sys/time.h>
#include <unistd.h>

int main() {
	struct timeval start, end;
	gettimeofday(&start, NULL);
	sleep(2);
	gettimeofday(&end, NULL);
	long seconds = end.tv_sec - start.tv_sec;
	long micros = end.tv_usec - start.tv_usec;
	printf("Time elpased is %f s.
", ((float)micros) / 1000000 + seconds);
	return 0;
}
原文地址:https://www.cnblogs.com/zhouyang209117/p/11226244.html