Two Java function can be use to calculate the elapsed time or execuiton time in java.
- System.currentTimeMillis()
- System.nanoTime()
Example:
System.currentTimeMillis()
long StartTime = System.currentTimeMillis(); //do some tasks long EndTime = System.currentTimeMillis(); long difference = EndTime - StartTime; System.out.println("Elapsed milliseconds: " + difference);
System.nanoTime()
long StartTime = System.nanoTime(); //do some tasks long EndTime = System.nanoTime(); long difference = EndTime - StartTime; System.out.println("Elapsed nanoseconds: " + difference);
No comments:
Post a Comment