Click to See Complete Forum and Search --> : [RESOLVED] quick and simple question


SepetPhalanx
04-15-2005, 08:47 PM
How would I have a message display at the end of a execution (right before it says "press any key to continue") that tells how long it took from one action to the end of the program's execution; not from beginning to end of execution.

7stud
04-17-2005, 02:03 AM
You should be able to do that using Date() objects. Correction: it looks like all the Date() methods are deprecated. So, you can use a Calendar() object instead. A Calendar() object gets the current time in milliseconds from the user's computer. So, you can get the time at some place in your code, and then you can get the time again at some later point in your code. However, you should be aware that a millisecond is a long time for a computer, and you may not register any elapsed time. Here is an example:
Calendar start = Calendar.getInstance();

for(int i =0; i<10000000; i++)
{
int calc = 10 * 50 / 3 * 4 / 2;
}

Calendar end = Calendar.getInstance();

long elapsed = end.getTimeInMillis() - start.getTimeInMillis();
System.out.println(elapsed);
Note: I had to run that loop 10 million times to register any elapsed time on my pc.