Skip to content

Instantly share code, notes, and snippets.

@renie
Created June 24, 2013 20:29
Show Gist options
  • Save renie/5853334 to your computer and use it in GitHub Desktop.
Save renie/5853334 to your computer and use it in GitHub Desktop.
Runtime counting
// 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