I usually use junit or ngunit to get a feel for runtime. It will tell you how long it took for the test to run in your ide separate from the console.
Or you can just log the start time and end time like so:
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
Date date = new Date();
System.out.println(dateFormat.format(date));
doStuff();
date = new Date();
System.out.println(dateFormat.format(date));
Or you can log the execution time:
long start = System.currentTimeMillis();
System.out.println("Going to call the method.");
doStuff();
System.out.println("Method execution completed.");
long elapsedTime = System.currentTimeMillis() - start;
System.out.println("Method execution time: " + elapsedTime + " milliseconds.");
You could use log4j if you want to write somewhere else (ie to a file) instead of get it all mixed up in the console
logger.info(dateFormat.format(date);
If you want to get fancier you can use AOP pointcuts to log start and end time around method execution with spring aop for example. Code is from here: http://veerasundar.com/blog/2010/01/spring-aop-example-profiling-method-execution-time-tutorial/
@Aspect
public class BusinessProfiler {
@Pointcut("execution(* com.veerasundar.spring.aop.*.*(..))")
public void businessMethods() { }
@Around("businessMethods()")
public Object profile(ProceedingJoinPoint pjp) throws Throwable {
long start = System.currentTimeMillis();
System.out.println("Going to call the method.");
Object output = pjp.proceed();
System.out.println("Method execution completed.");
long elapsedTime = System.currentTimeMillis() - start;
System.out.println("Method execution time: " + elapsedTime + " milliseconds.");
return output;
}
}
Printing to the console may be a bottleneck as it's blocking io - why do you want to print so much to the console? Is there value in this test?