Profiling Apex performance
In order to profile our Apex code, we need to take a series of measurements as to which governor resources have been utilized at multiple steps within the code’s execution path. The reason to take multiple recordings is so that we can ensure that we can identify where within the code the resources are being utilized.
Unlike other platforms, which allow the inspection of code, including memory usage, for different portions of the code, there is no such feature in Salesforce. We must perform our profiling manually and then run our analysis to determine what action to take. The way in which we will do this is through the use of the Limits
class.