How to calculate elapsed / execute time in Java
Written on January 28, 2009 at 5:56 am by
mkyong
Often time we need to calculate the program elapsed or execution time in performance test. Here i share a tiny example to calculate it in milliseconds
import java.util.Date; public class TimeMillisecond { public static void main(String[] argv) { long lStartTime = new Date().getTime(); //start time String sArray1[] = createArray(); //method execute long lEndTime = new Date().getTime(); //end time long difference = lEndTime - lStartTime; //check different System.out.println("Elapsed milliseconds: " + difference); } static String [] createArray(){ String sArray[] = new String [100000]; for(int i=0; i<100000; i++) sArray[i] = "Array " + i; return sArray; } }
Oracle Magazine (Free)
Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world\'s largest enterprise software company.
Publisher : Oracle Corporation


