# tools to analyse c++ code



## Johnny2Bad (Dec 8, 2014)

Unfortunately my FreeBSD server has died, so I'm stuck using Ubuntu 14.01. But I do not want to get off topic. I will be getting another one soon.

My query is, is there a port available to analyse the efficiency of C++ code? Back before the wheel was invented I used to use something on UNIX. What I am trying to do is build a weighted binary tree. I am aiming to make it as efficient as possible and I need a tool that will record the CPU usage for inserting, retrieving and deleting nodes. Preferably a command line tool.

Thanking you in advance,

Jonathan.


----------



## tankist02 (Dec 16, 2014)

For performance profiling I use valgrind with callgrind tool and visualize results with kcachegrind.


----------



## Crivens (Dec 16, 2014)

tankist02 said:


> For performance profiling I use valgrind with callgrind tool and visualize results with kcachegrind.


Good choice. The output files from valgrind from test runs can be also added to a versioning system, so that you can have an automatic regression test for your performance. Tools for comparison and evaluation are not available in a decent form, at least I could not find one when looking for it - maybe I looked in the wrong places. But being able to pin-point a performance regression is "very nice"(tm). It also may save your behind in some corporate environments when dealing with PHBs (those who need to, please look that up at dilbert).


----------



## rmoe (Dec 16, 2014)

What you want is to profile your code/algorithm implementation.

The superficial answer is hence: Use a profiler. And, btw., If in doubt linux has more - not less - development tools (readily) available.

Going a little deeper, it quickly becomes evident that it's more complex than "use a profiler". Not only because you need a quite profound understanding what you're doing but also for other reasons. One being that one and the same construct might be lightning fast on one processor and just average (or even lousy) on another one.

So, the real problem is elsewhere, it's you or, more precise, your real and exact desires and specifications. What, for instance, means "well balanced (performance)"? Does it mean balanced over insertion/retrieval? Or does it mean balanced "over the processors currently in wide-spread use"? Or yet something else.
And, of course, in that context details count, too. E.g. occasional insertion or massive series/junks of insertions? Oh and btw. insertions of _what_?

Learning more about profilers and their usage may anyway be a reasonable step to take for you. Consider them as measuring devices and keep in mind that, like in engineering in general, good measurements are based good problem specifications.


----------

