• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Simple runtime comparison

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Look at System.currentTimeMillis(). This is very common:
 
Hosh Nasi
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I was hoping it would be that easy.. Thanks!
 
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
reply
    Bookmark Topic Watch Topic
  • New Topic