I am writing a C project. Now I just doubt one function in the 开发者_StackOverflow社区whole project may be take the most of computational complexity. If I can make sure about this, I can further improve this function with a more clear target.
Or, is there any tools for this usage?? I mean to find the most "expensive" function in the whole program or project??
Any advices? Thanks!
The gprof profiler comes with the GCC compiler suite. Theres a manual for it here.
These tools are called "profilers". See this previous question.
The output from these can be difficult to interpret, so it might be wise to consider simpler options first. For example, you could write performance tests for particular areas of code you are concerned and simply timing them and seeing how they scale).
In general, it is impossible for any tool to find that out through statical analysis. Because if we could, we could also solve the halting problem.
Profilers allow you to analyse how the program behaves when run (against the input used then). This should be good enough for any real-world scenarios.
精彩评论