I don't know is there any direct methods to calculate
how much time taking to do a perticular task.
But still u can use ur own Timestamps inbetween ur
programming code to calculate the time ellapsed for
finish tht job.
Process flow for my example:-
1. Startup TimeStamp stored in a variable using new
Date().getTime() (new Date().getTime() will return the
current time in milliseconds since Jan 1, 1970 known
as "the epoch")
2. A Array with 10k elements intialized and unique
values are assigned for each element. It's not amazing
tht findining 10k values 10000k Random nos is not
enough to tick my time counter to high.
3. So i used one more for loop to sort the array &
finally i printed the MIN,MAX nos with appropriate
time Stamps.
import java.util.Date;
public class TimeCalc
{
public static void main(String args[])
{
long lngStart = new Date().getTime();
double dblRandom[] = new double[10000];
for(int i=0;i<10000;i++)
{
boolean flagDuplicate = true;
do
{
dblRandom[i] =
Math.round(Math.random()*10000000d);
flagDuplicate = false;
for(int j=0;j<i;j++)
{
if(dblRandom[i] == dblRandom[j])
{
flagDuplicate = true;
break;
}
}
}
while(flagDuplicate);
}
long lngArray = new Date().getTime();
System.out.println("Array created in " +
(lngArray-lngStart) + " milliseconds");
for(int i=0;i<dblRandom.length;i++)
{
for(int j=0;j<i;j++)
{
if(dblRandom[i]<dblRandom[j])
{
double dblTemp = dblRandom[i];
dblRandom[i] = dblRandom[j];
dblRandom[j] = dblTemp;
}
}
}
System.out.println("\t\tMin=" + dblRandom[0] + ",
Max=" + dblRandom[9999]);
System.out.println("Min,Max found in " + (new
Date().getTime()-lngArray) + " milliseconds");
System.out.println("Total Execution Time " + (new
Date().getTime()-lngStart) + " milliseconds");
}
}