tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 
 Tools and Libs > Google Guava > Basic > Stopwatch

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.

File Name  :  
com/bethecoder/tutorials/guava/base_tests/StopWatchTest.java 
Author  :  Sudhakar KV
Email  :  kvenkatasudhakar@gmail.com
   
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 = ; 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


                    Print

   



Books Recommendation

 
 
bl  br