Compute and display elapsed time of an operation : Timing « Development Class « Java

Compute and display elapsed time of an operation


public class Main {
  public static void main(String[] args) throws Exception{
    long startTime = System.currentTimeMillis();

    for (int i = 0; i < 10; i++) {
    long endTime = System.currentTimeMillis();
    float seconds = (endTime - startTime) / 1000F;
    System.out.println(Float.toString(seconds) + " seconds.");
//0.625 seconds.


Related examples in the same category

1.Get system time using System class
2.Class for program event timing
3.Get elapsed time in milliseconds
4.Get elapsed time in seconds
5.Get elapsed time in minutes
6.Get elapsed time in hours
7.Get elapsed time in days
8.Get time in milliseconds using Java Calendar convert between milliseconds and days
10.Get seconds since