user965369
user965369

Reputation: 5743

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

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?

Upvotes: 1

Views: 208

Answers (3)

Igor R.
Igor R.

Reputation: 15085

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

Upvotes: 1

Tony The Lion
Tony The Lion

Reputation: 63320

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.

Upvotes: 2

Joris Timmermans
Joris Timmermans

Reputation: 10988

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.

Upvotes: 1

Related Questions