I just profiled my program with gprof and got this:
100.01 0.01 0.01 23118 0.43 0.43 std::vector<int, std::allocator<int> >::operator=(std::vector<int, std::allocator<int> > const&)
Which confuses me, as it says that it is using 100.01% of the time using the = operator. Am i right guessing that this means it is just copying data all along and is there a limit of how much memory a program is allowed to use?
It looks like you profiled too short a run to get any useful data.
The way
gprofworks is that it periodically interrupts your code to see what function you were in at that instant. If the code isn’t running very long, it may only collect a small number of data points. In contrast,callgrindinstruments your code and tracks each function call and return and checks how much time was spent between hooks. This gives it a much fuller view, even if the run is short. This has a downside, it slows the program down quite a bit.Another advantage of
callgrindis that you can stop, start, and save its data collection. So if you don’t want to monitor your program’s startup or want to catch only the time it’s doing a particular thing, you can. Plus, there’s a tool calledkcachegrindthat can give you a great graphical view of the data you collected.If you can tolerate slowing your program down by a factor of four while you’re running it for testing, use
callgrindinstead — it’s part ofvalgrind.If you’re using Linux, your distribution probably has a
valgrindpackage and a package that includeskcachegrind(which may be called kdesdk or something else). It’s worth the time invested to learn how to use them (they are not as easy to get started with asgprof). I think you’ll find thekcachegrind‘s GUI impressive (look at this screenshot). And, as its name suggests, it can analyzecachegrindoutput too.