|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
|
#2
|
||||
|
||||
|
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... |
|
#3
|
||||
|
||||
|
You also have System.currentTimeMillis() which is probably the same granularity as Data (am not sure).
|
![]() |
| Viewing: Dev Articles Community Forums > Programming > Java Development > How to clock execution time |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|