由于我要测试线性筛法的速度,用上了C/C++精确计时.此时传统的clock()方法不够用了,我们需要另一种测量的办法,即CPUTicks/CPUFreq.如何实现呢?
#include <windows.h>
LARGE_INTEGER freq,start,stop;
QueryPerformanceFrequency(&freq);
QueryPerformanceCounter(&start);
//这样便得到一个CPUTick
//do some stuff....
QueryPerformanceCounter(&stop);
//注意LARGE_INTEGER是一个union起32bit low,high和64bit Quad的东西
//那么
double timeused=(double)(stop.QuadPart-start.QuadPart)/(double)freq.QuadPart;