vs2019下c语言获取代码运行时间(微秒时间差)

#include
#include 
int main() {
	int a[10002];
	int i = 0;
	double run_time;
	LARGE_INTEGER time_start;	//开始时间
	LARGE_INTEGER time_over;	//结束时间
	double dqFreq;		//计时器频率
	LARGE_INTEGER f;	//计时器频率
	QueryPerformanceFrequency(&f);
	dqFreq=(double)f.QuadPart;
	QueryPerformanceCounter(&time_start);	//计时开始
	for( i = 1; i <= 10000; i++)a[i]=i;	//要计时的程序
	QueryPerformanceCounter(&time_over);	//计时结束
	run_time=1000000*(time_over.QuadPart-time_start.QuadPart)/dqFreq;
	//乘以1000000把单位由秒化为微秒,精度为1000000/(cpu主频)微秒
	printf("\nrun_time:%fus\n",run_time);
	return 0;
}

你可能感兴趣的:(VS)