Compute and display elapsed time of an operation

Sometimes you want to compute the time a certain operation takes, which can be done by using the currentTimeMillis() method of the System class.
The value returned is the current time in milliseconds and by calling the method before and after the operation you can compute the difference in time,
which is the time of the operation.
The example below performs and operation by looping from 0 to 9 and in each loop makes the thread sleep for 60 milliseconds and then displays the time elapsed
between the start and the end of this operation.

The output should look something like this:

Search for more Java info on this site here:
Custom Search

Please type any questions here.