Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Is it possible to calulate execution time?
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
supahsain08




PostPosted: Mon May 26, 2008 9:52 am   Post subject: Is it possible to calulate execution time?

Hello, is it possible to calculate the time it took the program to execute

Thanks
btw i am using Jcreator IDE
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Mon May 26, 2008 11:04 am   Post subject: RE:Is it possible to calulate execution time?

The term is benchmark(ing)

There are usually fancy libraries available for that, but the bottom line is that you simply need to record the current time in a variable, run whatever, record the current time afterwards, and take the difference.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
rizzix




PostPosted: Mon May 26, 2008 11:05 am   Post subject: RE:Is it possible to calulate execution time?

Hmm, well depending on whether you want to calculate the startup time as well you'd have to do this in two different ways.

If you don't care about the jvm startup time, you can make use of the System.currentTimeMillis(); or System.nanoTime(); methods.

Use them at the beginning and end of your main() method. Something like this:
code:
long start_time = System.nanoTime();

// rest of your code in `main`

System.out.printf("Time elapsed in ns: %d\n", System.nanoTime()  - start_time);


Edit: Ah, Tony beat be to it. Razz
supahsain08




PostPosted: Thu May 29, 2008 5:58 pm   Post subject: RE:Is it possible to calulate execution time?

Thanks Smile
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 4 Posts ]
Jump to:   


Style:  
Search: