The Poor Man's Profiler is a very simple way to know the time spent in some chosen parts of your code.
Accuracy is as good as System.currentTimeMillis() is accurate.
- A wrapping live template is used to easily wrap the code to watch.
{
final long before = System.currentTimeMillis();
$SELECTION$
final long timeTaken = System.currentTimeMillis()-before;
HashTimer.addTimeFor("$timerId$", timeTaken);
}
|
- A class - tools.HashTimer - is used to accumulate the data.
- Results are obtained by printing the accumulated data :
System.out.println( "\n" + HashTimer.results () );
|
new UI() : 7 calls - 2624 ms
new Model() : 7 calls - 120 ms
point 2 : 10 calls - 100 ms
|
- Add the live template above in your IDEA config.
(suggested name : timer, or pmp)
- Add the tools.HashTimer class to your project.
(hint: turn it into a File Template)
(Tip : select methodName() as the template variable $timerId$ default value)
- Wrap the code to watch with timing code :
- select the area to watch,
- [Shift-Ctrl-J]
- enter a timer id
ex. new UI(), method(), properties loading, ..
- select the timer live template
- Print the result, when main() exits :
public static void main ( String[] args )
{
...
System.out.println( "\n" + HashTimer.results () );
}
- The accuracy depends 100% on System.currentTimeMillis().
|
|