Stopwatch
Google Guava is a java library with lot of utilities and reusable components.
This requires the library guava-10.0.jar to be in classpath.
The following example shows using Stopwatch class.
package com.bethecoder.tutorials.guava.base_tests;
import java.util.concurrent.TimeUnit;
import com.google.common.base.Stopwatch;
public class StopWatchTest {
/**
* @param args
*/
public static void main ( String [] args ) {
//Start the Stopwatch
Stopwatch stopWatch = new Stopwatch () .start () ;
//Some operation !!!
for ( int i = 0 ; i < 10 ; i ++ ) {
System.out.print ( "BTC " ) ;
}
//Stop the watch and get elapsed time
stopWatch.stop () ;
System.out.println ( "\nTime taken : " + stopWatch.elapsedTime ( TimeUnit.NANOSECONDS ) + " ns" ) ;
}
}
It gives the following output,
BTC BTC BTC BTC BTC BTC BTC BTC BTC BTC
Time taken : 284673 ns