任务耗时如何优雅的打印,看完本文你就明白了!~
import cn.hutool.core.date.StopWatch;
import cn.hutool.core.lang.Console;/*** 优雅打印出任务耗时*/
public class Main {public static void main(String[] args) throws Exception{StopWatch stopWatch = new StopWatch("任务名称");// 任务1stopWatch.start("任务一");Thread.sleep(1000);stopWatch.stop();// 任务2stopWatch.start("任务二");Thread.sleep(2000);stopWatch.stop();// 打印出耗时Console.log(stopWatch.prettyPrint());}
}
控制台打印结果: