Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

system.millisec ()

  Asked By: Lloyd    Date: Jun 25    Category: Java    Views: 1766

i have stuck in the problem ..actually i am creating an application
it is taking so much time to display the page .i want to know
actually how much time it is taking .is there any some methood
through which i can know the time of my application..inmillesec . i
have tried with system.millisec ()..but this is not working



1 Answer Found

Answer #1    Answered By: Allan Bailey     Answered On: Jun 25

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;
dblRandom[i] =
flagDuplicate = false;

for(int j=0;j<i;j++)
if(dblRandom[i] == dblRandom[j])
flagDuplicate = true;


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++)
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");

Didn't find what you were looking for? Find more on system.millisec () Or get search suggestion and latest updates.