This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Run-Time of the algorithm.. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Run-Time of the algorithm.." Watch "Run-Time of the algorithm.." New topic
Author

Run-Time of the algorithm..

Steve De Costa
Ranch Hand

Joined: Jun 04, 2007
Posts: 33
I've written some code/algorithm and I'm trying to check its run-time.

Any idea if there is an effective way of doing it?

The only thing I could think of was putting my algorithm between the following two lines


System.out.println(System.currentTimeMillis());
//...then the piece of code goes here...
System.out.println(System.currentTimeMillis());
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38064
    
  22
You may prefer to use the System method which gets time in nanoseconds, called something like nanoTime() (look in the API for the correct spelling).Also note how long it takes to run when there is no code between the two nanoTime calls. Note that timings vary quite a bit on successive runs, even when everything else appears unchanged.
 
Consider Paul's rocket mass heater.
 
subject: Run-Time of the algorithm..
 
Similar Threads
ArrayList
Calculationg execution time
I want to Read and copy 800 MB file. Any efficient way.
for loop optimization
Multi Threading