I'm new to C/C++ and facing a performance issue that my program is running very slow. I want to find what's the hot spot is to reduce the overall execution time for my code. What's the most popular and the easiest way to profile a C/C++ application in Windows? I've been very amazed by how easy it is to profile a .NET application using Mini Proler. Do we have any similiar library in C/C++ that gives us that high quality and reliable of result with a minimal added code? Or is there any tool that is similiar to RedGate ANTS performance profiler that also provider insightful information about the running code?
-
2I think valgrind can do that. Maybe there is a port to windows? – Burkhard Jan 25 '13 at 19:04
-
http://www.codersnotes.com/sleepy – Frank Osterfeld Jan 25 '13 at 21:55
2 Answers
Intel's VTune or AMD's CodeAnalyst are both very good tools. On Linux, Perf or OProfile will do the same thing.

- 126,704
- 14
- 140
- 227
While you are hunting around for a profiler, run the program in the debugger IDE and try this method.
Some programmers rely on it. There's an example here of how it is used.
In that example here's what happens. A series of problems are found and removed.
The first iteration saved 33% of the time. (Speedup factor 1.5)
Of the time remaining, the second iteration saved 17%. (Speedup factor 1.2)
Of the time remaining, the third iteration saved 13%. (Speedup factor 1.15)
Of the time remaining, the fourth iteration saved 66%. (Speedup factor 2.95)
Of the time remaining, the fifth iteration saved 61%. (Speedup factor 2.59)
Of the time remaining, the sixth iteration saved 98%. (Speedup factor 45.9)
All those big-percent changes were not big percents of the original time, but they became so after other problems were removed. The total amount of time saved from the original program was over 99.8%. The speedup was 730 times.
Most programs that have not gone through a process like this have lots of room for speedup, but you're not likely to realize it using only a profiler because all they do is make measurements. They don't always point out to you what you need to fix, and each problem you miss keeps you from getting the really significant speedup.
To put it another way, the final speedup factor is the product of all those individual factors, and if any one of them is missed, it is not only absent from the product, but it reduces the following factors. That's why, in performance diagnosis, "good enough" is not good enough. You have to find every problem.

- 1
- 1

- 40,059
- 14
- 91
- 135