在spring中使用StopWatch

    @Test
    public void stopWatch(){
        StopWatch stopWatch = new StopWatch();
        stopWatch.start("selectAll");

        List list = userMapper.selectAll();

        stopWatch.stop();

        stopWatch.start("findByName");
        List byNameList = userMapper.findByName("b7");

        stopWatch.stop();
        System.out.println(stopWatch.prettyPrint());
    }

展示为:

StopWatch '': running time (millis) = 107
-----------------------------------------
ms     %     Task name
-----------------------------------------
00100  093%  selectAll
00007  007%  findByName

一个StopWatch可以start多个task, 但是同一时间只能运行一个task, (所以stopWatch.stop()的时候不需要指定名称)

你可能感兴趣的:(在spring中使用StopWatch)