aspose file tools*
The moose likes Beginning Java and the fly likes Simple runtime comparison Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Simple runtime comparison" Watch "Simple runtime comparison" New topic
Author

Simple runtime comparison

Hosh Nasi
Ranch Hand

Joined: Sep 10, 2004
Posts: 44
I want to do a simple runtime test on a program I just completed. I am going to iterate through it 1000 times and I want to capture the time at start and at end then subtract them to determine how long the program ran.

I want to basically run it for enough time to see what performance issues it has. Say garbage collection.

thanks!
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Look at System.currentTimeMillis(). This is very common:


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Hosh Nasi
Ranch Hand

Joined: Sep 10, 2004
Posts: 44
I was hoping it would be that easy.. Thanks!
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
So what part of this do you need help with exactly? I assume you need to know how to get the current time at the beginning and end of your program. Is that correct? With a little bit of work, you can find help with such things by browsing the Java API documentation. In particular, you can use java.util.Date. Its default constructor initializes the Date object with the current time.

I guess you also need to find a way to subtract the beginning and ending time. Unfortunately, I haven't found anything yet, but if you browse through the above links, you might be able to find something that I'm missing.

Good luck!

Layne


Java API Documentation
The Java Tutorial
 
 
subject: Simple runtime comparison