统计输出总耗时
StopWatch sw = new StopWatch(); sw.start(); // long task simulation try { Thread.sleep(1000); } catch (Exception e) { e.printStackTrace(); } sw.stop(); System.out.println(sw.getTotalTimeMillis());
以优雅的格式打出所有任务的耗时以及占比
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());