One operation is always fast. Measured CPU utilization, the operation is performed several thousand times, or even a million or a billion times. Therefore, you want to keep track of all kinds of loops and highly recursive calls.
It is often not obvious that something executes a million times, because the obvious loop only executes a hundred times. But it calls a function that performs something a hundred times, which contains another function that performs the operation a hundred times. So you end up with something running a million times. And in a web application, it is multiplied by the number of simultaneous requests.
Since itβs not easy for you to discover real βhot spotsβ, you probably want to use a special Java performance analysis tool to examine your application. This way you will find out which patterns have processor intensity and which don't.
Another thing in Java, if you allocate a lot of memory (be it a few large pieces and many small pieces) that cannot be quickly released, then garbage collection can become a processor swamp. Using a ton of string (for example, when processing XML) may be such a reason.
But it is best to use a tool for analysis.
source share