IntelliJ Community . PoorManProfiler

 
PoorManProfiler 

HOME INDEX SEARCH CHANGES GO  
What it is :

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.

How it works :

  1. 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);
      }
  1. A class - tools.HashTimer - is used to accumulate the data.
  2. Results are obtained by printing the accumulated data :
    
             System.out.println( "\n" + HashTimer.results () );

What does the result look like :

    
              new UI()    : 7 calls - 2624 ms
              new Model() : 7 calls - 120 ms
              point 2     : 10 calls - 100 ms

How to install :

  1. Add the live template above in your IDEA config.
    (suggested name : timer, or pmp)
  2. 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)

How to use :

  1. 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
  2. Print the result, when main() exits :
    public static void main ( String[] args )
    {
        ...        
        System.out.println( "\n" + HashTimer.results () );        
    }

Limitations

  • The accuracy depends 100% on System.currentTimeMillis().

Attachment: sort Action: Size: Date: Who: Comment:
HashTimer.java action 3105 27 Sep 2002 - 11:29 AlainRavet HashTimer?.java
TESTC_HashTimer.java action 1623 27 Sep 2002 - 11:31 AlainRavet  

e d i t a t t a c h r e f - b y d i f f s m o r e
Have ideas, requests, problems regarding this site? Send feedback.
Copyright © 2000-2003 by the contributing authors. All materials at intellij.org are the property of the contributing authors.