#include <Windows.h>
LARGE_INTEGER freq,start,end;
QueryPerformanceFrequency(&freq);
QueryPerformanceCounter(&start);
QueryPerformanceCounter(&end);
outfile<<"运行时间:"<<(end.QuadPart-start.QuadPart)*1.0/freq.QuadPart<<endl;
本文介绍如何使用Windows API函数QueryPerformanceCounter来精确计算程序的运行时间,并通过简单的数学运算将其转换为人类可读的单位。此方法适用于需要高精度计时的应用场景。
#include <Windows.h>
LARGE_INTEGER freq,start,end;
QueryPerformanceFrequency(&freq);
QueryPerformanceCounter(&start);
QueryPerformanceCounter(&end);
outfile<<"运行时间:"<<(end.QuadPart-start.QuadPart)*1.0/freq.QuadPart<<endl;

被折叠的 条评论
为什么被折叠?