调试测试某一段代码的执行

AutoTimeStamp类
  1. classAutoTimeStamp
  2. {
  3. public:
  4. AutoTimeStamp(constchar*pcLog)
  5. {
  6. m_fTimeBegin= DxGetCurrentTimeInSec();
  7. m_pcLog= pcLog;
  8. }
  9. ~AutoTimeStamp()
  10. {
  11. floatfTime =DxGetCurrentTimeInSec();
  12. floatfTimeDelta =fTimem_fTimeBegin;
  13. charstr[100];
  14. //if(fTimeDelta > 0.001)
  15. //{
  16. sprintf_s(str,“%s:%f”,m_pcLog,fTimeDelta);
  17. cout<< str<<endl;
  18. //}
  19. }
  20. floatm_fTimeBegin;
  21. constchar*m_pcLog;
  22. };
  23. #define DEFINE_AUTO_TIMESTAMP(x)AutoTimeStampkTimeStamp(x);
用到的获取当前时间的函数
  1. floatDxGetCurrentTimeInSec()
  2. {
  3. staticboolbFirst =true;
  4. staticLARGE_INTEGERfreq;
  5. staticLARGE_INTEGERinitial;
  6. if(bFirst)
  7. {
  8. QueryPerformanceFrequency(&freq);
  9. QueryPerformanceCounter(&initial);
  10. bFirst= false;
  11. }
  12. LARGE_INTEGERcounter;
  13. QueryPerformanceCounter(&counter);
  14. return(float)((long double)
  15. (counter.QuadPartinitial.QuadPart) /
  16. (longdouble)freq.QuadPart);
  17. }

使用方法如下:

测试
  1. voidmain()
  2. {
  3. set<int>kSet;
  4. kSet.insert(1);
  5. for(inti = 0;i< 10000; ++i)
  6. {
  7. kSet.insert(i);
  8. }
  9. {
  10. DEFINE_AUTO_TIMESTAMP(“find10000001 10000times use time:”)
  11. for(inti = 0;i< 10000; ++i)
  12. {
  13. if(kSet.find(10000001)!= kSet.end());
  14. }
  15. }
  16. }

发表评论

邮箱地址不会被公开。 必填项已用*标注

* Copy This Password *

* Type Or Paste Password Here *