直接上代码:
public static void main(String[] args) throws InterruptedException {
StopWatch stopWatch = new StopWatch("StopWatch测试");
stopWatch.start("2000L");
Thread.sleep(2000L);
stopWatch.stop();
stopWatch.start("3000L");
Thread.sleep(3000L);
stopWatch.stop();
System.out.println(stopWatch.getTotalTimeMillis());
System.out.println(stopWatch.prettyPrint());
}
打印结果如下:
5003
StopWatch ‘StopWatch测试’: running time = 5003617084 ns
--------------------------------------------- ns % Task name
--------------------------------------------- 2001746042 040% 2000L 3001871042 060% 3000L