Testing performance of C++ code
What free tools could I use to test the performance of C++ code in Linux? Basically I want to identify the bottleneck of the code and improve on the performance. My application mainly involves computational code using the data from the network. So I would like to improve the speed of execution of the code.
Thank开发者_如何学Pythons.
For typical performance benchmarking this is what i use.
- gprof/oprofile - for CPU intensive profiling of your code.
- netstat/ethereal - for network statistics
- iostat/sar - for I/O
- vmstat - for memory
- mpstat/sar - for cpu usage
Now u can isolate the problems based on the output of these tools.
For eg:- if I/O is constant and within limits u can eliminate I/O as a problem. If CPU usage is heavy as shown my mpstat then get into profiling using gprof/oprofile.
Without the use of all of them together for different runs, its difficult to identify the bottleneck.
Note: U can write a script to run all of them together and store the results in designated folders for each run.
I recommend valgrind for
- cpu usage, callgrind submodule (source line granularity)
- memory leaks
- building call graphs
- some advanced issues like finding problems in multithread locking mechanism
The callgrind output can be visually displayed via KCacheGrind.
By far the best profiler for Linux that I know of is Zoom. Although it's a commercial product it's not too expensive and you can get a free 30 day evaluation licence on request
As @Paul says, give Zoom a try.
Personally, I use this method, which works for these reasons, and Zoom approximates it. It is a technique that some programmers have independently discovered.
I'm also told OProfile can do it, but you have to know what you need to make it do.
精彩评论