Java Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingJava Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old June 20th, 2005, 10:47 AM
maralbjo maralbjo is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 13 maralbjo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 49 m 27 sec
Reputation Power: 0
How to clock execution time

I would like to check the execution time taken to perform a specific task (code block).

How do I do that? Do I have to start a new thread for that or can I create an object of some sort?

Any helps/hints appreciated!

maralbjo

Reply With Quote
  #2  
Old June 20th, 2005, 02:50 PM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,890 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 14 m 9 sec
Reputation Power: 8
How about something along the lines of:
Code:
Date startTime = ...;

/* [block of code] */

Date endTime = ...;

// Compute the difference between the dates
long diff = startTime.getTime() - endTime.getTime();

long min = diff/(60 * 1000);
long hours = min/60;
min = min%60;
long days = hours/24;
hours = hours%24;

System.out.println("Elapsed time is:"+" days: "+days+" hours: "+hours+" min: "+min)


It's off the top of my head and untested...

Reply With Quote
  #3  
Old November 30th, 2005, 04:18 AM
Icon's Avatar
Icon Icon is offline
Command Line Warrior
Click here for more information. Click here for more information
 
Join Date: Sep 2005
Posts: 748 Icon User rank is Private First Class (20 - 50 Reputation Level)Icon User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Week 3 Days 13 h 56 m 25 sec
Reputation Power: 4
You also have System.currentTimeMillis() which is probably the same granularity as Data (am not sure).

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingJava Development > How to clock execution time


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT