以优雅的格式打出所有任务的耗时以及占比
使用StopWatch
import org.springframework.util.StopWatch;
public class SpringStopWatchExample3 {
public static void main (String[] args) throws InterruptedException {
StopWatch sw = new StopWatch();
sw.start("A");
Thread.sleep(500);
sw.stop();
sw.start("B");
Thread.sleep(300);
sw.stop();
sw.start("C");
Thread.sleep(200);
sw.stop();
System.out.println(sw.prettyPrint());
}
}
输出
StopWatch '': running time (millis) = 1031
-----------------------------------------
ms % Task name
-----------------------------------------
00514 050% A
00302 029% B
00215 021% C
`