Spring框架有一个优秀的
StopWatch class:
StopWatch stopWatch = new StopWatch("My Stop Watch");
stopWatch.start("initializing");
Thread.sleep(2000); // simulated work
stopWatch.stop();
stopWatch.start("processing");
Thread.sleep(5000); // simulated work
stopWatch.stop();
stopWatch.start("finalizing");
Thread.sleep(3000); // simulated work
stopWatch.stop();
System.out.println(stopWatch.prettyPrint());
这产生:
StopWatch 'My Stop Watch': running time (millis) = 10000
-----------------------------------------
ms % Task name
-----------------------------------------
02000 020% initializing
05000 050% processing
03000 030% finalizing