I'm using MFC in Visual Studios. 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. Can this be done with breakpoints?
-
1Possibly related: http://stackoverflow.com/q/12340824/596781 – Kerrek SB Sep 11 '12 at 11:45
3 Answers
No, use QueryPerformanceCounter
(docs) for accurate measurements of speed. 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.
Using a good profiler is a better idea, or just use clock_t
to measure.

- 61,704
- 67
- 242
- 415
-
This may be dangerous on processors with speed scaling - you don't have a uniform length of a tick. – Joris Timmermans Sep 11 '12 at 11:41
-
@MadKeithV ah, I didn't know that. What would you use instead then? I'm sure there's tools, not sure if valgrind or something measures speed – Tony The Lion Sep 11 '12 at 11:42
-
If the operations are long enough (in the milliseconds) just plain clock time, otherwise it's time to break out the profiler. – Joris Timmermans Sep 11 '12 at 11:43
-
One good way to measure efficiency of an operation is by profiling (see e.g. 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" (e.g. your platform's GetTime equivalent) to time the duration of calls - e.g. if a single operation takes multiple milliseconds. 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.

- 1
- 1

- 10,814
- 2
- 49
- 75
If you've got Ultimate edition, it has quite decent built-in performance profiler. Otherwise, use an external profiler.

- 14,716
- 2
- 49
- 83