GetTickCount() 用于 int main 中的多个函数
我试图在一段非常大的代码中分别使用 GetTickCount() 对多个函数进行计时,以找出瓶颈的确切位置。我可以成功地对整段代码进行计时。我正在努力解决的是在哪里添加计时函数来测量每个单独函数的时间。我是否在声明函数或定义函数时或在调用函数的 main () 内部插入计时器。 任何帮助将不胜感激。 谢谢。
I'm trying to time multiple functions using GetTickCount() separately in a very large piece of code to find where exactly the bottlenecks are. I can successfully time the whole piece of code. What I'm struggling to work out is where do I add the timing function to measure time for each individual function. Do I insert the timer when the functions are declared or when they are defined or inside the main () where they are being called.
Any help would be really appreciated.
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以在运行时调用它们时对它们进行计时,例如:
测量代码计时的更好方法是使用探查器,而不是在代码本身中编写逻辑。探查器挂钩到运行时进程并将其自己的代码插入到函数本身中。然后,它不仅可以跟踪函数运行的时间,还可以跟踪它们被调用的次数、哪些函数调用了哪些函数、记录调用堆栈等。所有这些都无需编写任何额外的代码。
You time them when they are called at runtime, eg:
A better way to measure code timings is to use a profiler instead of writing logic in the code itself. A profiler hooks into the runtime process and inserts its own code inside the functions themselves. Then it can track not only how long the functions take to run, but also how many times they are called, what functions call which functions, log call stacks, etc. All without writing any extra code.