我知道这个问题已被问过几次,但是没有一个真的能帮助我,所以再问一遍.
我正在使用Windows XP并运行visual studio c ++ 2008.
我正在寻找的所有代码都使用time.h但我认为可能在这里没有正常工作,因为结果让我怀疑.
所以这就是我想要的.
star time = get time some how (this is my question)
my code
end time = get time some how (this is my question)
time passed = start time - end time
Run Code Online (Sandbox Code Playgroud)
这是我用来以毫秒为单位打印时间的方法.
void StartTimer( _int64 *pt1 )
{
QueryPerformanceCounter( (LARGE_INTEGER*)pt1 );
}
double StopTimer( _int64 t1 )
{
_int64 t2, ldFreq;
QueryPerformanceCounter( (LARGE_INTEGER*)&t2 );
QueryPerformanceFrequency( (LARGE_INTEGER*)&ldFreq );
return ((double)( t2 - t1 ) / (double)ldFreq) * 1000.0;
}
Run Code Online (Sandbox Code Playgroud)
像这样使用它:
_int64 t1;
StartTimer( &t1 );
// do some stuff
printf( "Time = %.3f\n", StopTimer( t1 ));
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4391 次 |
| 最近记录: |