简体   繁体   English

如何在Visual C ++中以ns,ps或clk周期衡量执行时间?

[英]How to measure execution time in ns, ps or clk cycles in visual c++?

有没有一种方法可以衡量在Visual C ++中我的C ++代码的特定部分花费了多少时间?

Do you need it for debug only or do you need it for the application you are making? 您仅需要将其用于调试,还是将其用于正在创建的应用程序? I can tell you a technique for debug only: 我可以告诉您一种仅用于调试的技术:

  • Put breakpoint in the starting code line and another in final one. 将断点放在起始代码行中,并将断点放在最后一行中。
  • When the execution stops at the first breakpoint, in the Watch Window watch for the $clk variable. 当执行在第一个断点处停止时,在“监视窗口”中监视$clk变量。
  • It almost certainly has a value different of Zero. 几乎可以肯定它的值与零不同。 Define it to Zero. 将其定义为零。
  • Then wait for the execution to flow to the second breakpoint. 然后等待执行流到第二个断点。 Now look to the Watch Window and the $clk variable has the time elapsed. 现在看一下“监视窗口”, $clk变量具有经过的时间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM