Created
June 24, 2013 20:29
-
-
Save renie/5853334 to your computer and use it in GitHub Desktop.
Runtime counting
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// start method | |
long startFullTime = System.currentTimeMillis(); | |
//step1 begin | |
long startStep1Time = System.currentTimeMillis(); | |
// some logic of step 1 here | |
long endStep1Time = System.currentTimeMillis(); | |
//step1 end | |
//step2 begin | |
long startStep2Time = System.currentTimeMillis(); | |
// some logic of step 2 here | |
long endStep2Time = System.currentTimeMillis(); | |
//step2 end | |
//ending method | |
long endFullTime = System.currentTimeMillis(); | |
long fullTime = endFullTime - startFullTime; | |
System.out.println("Full Time: "+fullTime+"ms"); | |
System.out.println("Step1 time: "+100L*(((double)endStep1Time - (double)startStep1Time)/(double)fullTime)+"% -> "+(endStep1Time - startStep1Time)+"ms"); | |
System.out.println("Step2 time: "+100L*(((double)endStep2Time - (double)startStep2Time)/(double)fullTime)+"% -> "+(endStep2Time - startStep2Time)+"ms"); | |
// method return | |
//end method | |
/* | |
Return will be something like: | |
Full Time: 150ms | |
Step1 time: 35.48% -> 53ms | |
Step2 time: 64.52% -> 97ms | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment