直接上代码,简单易懂
StopWatch watch = new StopWatch("测试代码运行时间百分比");
watch.start("校验");
if (true) {
return null;
}
watch.stop();
watch.start("查询找数据");
List nameList = mapper.getById(1);
watch.stop();
watch.start("更新数据");
mapper.update(User);
watch.stop();
System.out.println(stopWatch.prettyPrint());
最后看控制打印出的信息非常直观
StopWatch '': running time (millis) = 215 //总共消耗时间 ----------------------------------------- ms % Task name ----------------------------------------- 00001 000% 校验 //占用的百分比 00107 050% 查询找数据 00107 050% 更新数据



