用C ++代码计算时间 [英] Calculating time by the C++ code
本文介绍了用C ++代码计算时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道这个问题已经被问过几次了,但是没有一个人真的在帮助我,所以再问一次。
I know this question has been asked few times over SO but none of them is really helping me out, so asking again.
我正在使用Windows XP并运行Visual Studio C ++ 2008。
I am using windows xp and running visual studio c++ 2008.
我正在寻找的所有代码都在使用time.h,但我认为这可能在这里无法正常工作,因为结果使我感到怀疑。
All the code which i am looking is using time.h but i think may be its not working correctly here, because results are making me suspicious.
所以这就是我想要的。
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
推荐答案
这是我使用的
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;
}
像这样使用:
_int64 t1;
StartTimer( &t1 );
// do some stuff
printf( "Time = %.3f\n", StopTimer( t1 ));
这篇关于用C ++代码计算时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文