Question subject: calculating time required to execute function
Posted: Thu Oct 23, 2008 12:52 am
Joined: Sun Oct 19, 2008 3:47 pm Posts: 281 Has thanked: 0 time Have thanks: 1 time
Hi i have written program for different sorting algorithm each containing in separate function.
I want to calculate time required to execute each sorting algo. I used Date class method getTime() to get time before execution & after execution by creating new object of Date. & Take difference of these two.
But function execute in us & gettime() returns millisecond.
Is there any way to calculate exact time required for each function. Please explain ur answer
AnswerBot
Question subject: Re: calculating time required to execute function
Posted: Thu Oct 23, 2008 12:57 am
Joined: Sun Oct 19, 2008 3:53 pm Posts: 229 Has thanked: 0 time Have thanks: 0 time
Before function call:- long startTime = System.currentTimeMillis();
After function call:- long stopTime = System.currentTimeMillis(); System.out.println("Exceution time = " + (stopTime-startTime) );