I need to measure the time it takes for a function to complete in Java. How can I do that?
Note:
I want to measure the function's time consumption, not that of the full program.
I need to measure the time it takes for a function to complete in Java. How can I do that?
I want to measure the function's time consumption, not that of the full program.
Here is how can compute the elapsed time.
Use a profiler.
System.nanoTime should be used to accurately measure the delta between two times for microbenchmarks.
System.currentTimeMillis returns the current time in milliseconds. You can use this to get the current time. This may be useful on older VMs or for longer running processes.
this analogue stopwatch is another option for us too... Check on Java2s.com here.