Simple code to time the execution of a simple program?

vlg
vlg used Ask the Experts™
on
Hello all
I have a little java program that goes out to the web and comes back with some info, and I'd like to time how long it takes - from the time I start the program, until it exits, having retrieved the data.
I'm hoping I can just add a few lines into my simple program, maybe getting the system time at the beginning and end of the main function, but I don't know how, so that's what the points are for -  

Thanks

v
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
You can use the currentTimeMillis method in the system class. It gives you a readout in milliseconds. So at the beginning you would do something like:

long starttime=System.currentTimeMillis();

and then at the end:

long tottime=System.currentTimeMillis()-starttime;
long sec=tottime/1000;
long ms=tottime%1000;
System.out.println("Time take: "+sec+"."+ms+" seconds.");

vlg

Author

Commented:
that's what i was looking for, thanks

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial