There are certain generally accepted beliefs in this matter that I would suggest you carefully study.
One of them is that the best (if not the only) way to find performance problems is to measure the time that each subroutine executes and how many times it is called.
It is top to bottom. This is due to the belief that the forest is more important than trees. It is based on the myths of "code speed" and "bottlenecks." This is not very scientific.
The performance problem is more like an error than a quantitative one. What he does wrong is a waste of time and needs to be fixed. It is based on a simple observation:
Slowness consists of time spent on bad causes.
To find it, give an example of the state of the program by random interruptions of hourly time and investigate their causes.
If something causes slowness, then this fact itself provides it to your samples. Therefore, if you take enough samples, you will see this. You will find out approximately how much time it costs you, for a fraction of the samples that show it.
A good way to tell if it is well spent from time to time is to look carefully at the call stack. Each function call on the stack has a hidden reason, and if any of these reasons is bad, then the reason for the whole pattern is bad.
Some profilers will tell you, at the instruction level, that each statement is worth your while.
Personally, I just accidentally stop the program several times. Any challenges that appear on multiple samples are likely candidates for suspicion. It will never work.
You can say, "This is not accurate." This is very accurate. It pinpoints the instructions causing the problem. It does not give you 3 decimal places of precision of time. That is, it is disgusting to measure, but excellent for diagnosis.
You can say, "What about recursion?" Well, what about this?
You can say: "I think this can only work on toy programs." That would be just a wish. In fact, large programs tend to have more performance problems because they have deeper stacks, thus more opportunities for calls with bad reasons, and the selection finds them just fine, thanks.
Sorry I'm crazy. I just hate seeing myths in what should be a scientifically sound field.
MORE