- public static void main(String[] args) throws InterruptedException {
- StopWatch stopWatch = new StopWatch("测试StopWatch");
- stopWatch.start("任务1");
- // 任务1花费1000毫秒
- Thread.sleep(1000);
- stopWatch.stop();//必须要stop,不然下一个任务无法开始计时
-
- stopWatch.start("任务2");
- // 任务2花费2000毫秒
- Thread.sleep(2000);
- stopWatch.stop();
- System.out.println(stopWatch.prettyPrint(TimeUnit.MILLISECONDS));
- }
