简体   繁体   English

在Visual C ++中测量操作速度的最佳方法

[英]Best way to measure the speed of an operation in Visual C++

I'm using MFC in Visual Studios. 我在Visual Studios中使用MFC。 I wondered what the best way to measure the speed/efficiency of an operation (eg Function A vs Function B) working in this specific IDE. 我想知道在这个特定的IDE中测量操作(例如,功能A与功能B)的速度/效率的最佳方法是什么。 Can this be done with breakpoints? 这可以用断点来完成吗?

No, use QueryPerformanceCounter ( docs ) for accurate measurements of speed. 不,使用QueryPerformanceCounterdocs )来准确测量速度。 From comments from @MadKeithV, this seems to not be a good solution, as CPU speed scaling (reducing CPU speed according to current load) may change CPU tick length. 根据@MadKeithV的评论,这似乎不是一个好的解决方案,因为CPU速度缩放(根据当前负载降低CPU速度)可能会改变CPU滴答长度。

Using a good profiler is a better idea, or just use clock_t to measure. 使用好的分析器是一个更好的主意,或者只是使用clock_t进行测量。

One good way to measure efficiency of an operation is by profiling (see eg How is profiling different from logging? ) - profiling is intended to show you where time is being spent in your program, specific functions, lines or even statements. 测量操作效率的一个好方法是通过分析(参见例如, 如何分析不同于日志记录? ) - 分析旨在向您显示在程序,特定函数,行甚至语句中花费的时间。

If your operations take long enough you can also use simple "wall clock time" (eg your platform's GetTime equivalent) to time the duration of calls - eg if a single operation takes multiple milliseconds. 如果您的操作需要足够长的时间,您还可以使用简单的“挂钟时间”(例如您的平台的GetTime等效时间)来计算呼叫的持续时间 - 例如,如果单个操作需要几毫秒。 Beware that this can be very tricky to break down into actual performance in the presence of multithreading - you should know exactly what you are measuring. 请注意,在存在多线程的情况下分解为实际性能非常棘手 - 您应该确切地知道您在测量什么。

If you've got Ultimate edition, it has quite decent built-in performance profiler. 如果你有终极版,它有相当不错的内置性能分析器。 Otherwise, use an external profiler. 否则,请使用外部探查器。

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

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