还在System.currentTimeMillis()嘛?你可以知道spring提供的StopWatch

StopWatch代码及运行效果
博客介绍了StopWatch,其意为“秒表”,随后直接给出代码并提及运行后的效果。

StopWatch

特意的百度了下 是“秒表的意思”

废话不多说 直接上代码

 public static void main(String[] args) throws InterruptedException {
        // 定义一个计数器

        StopWatch stopWatch = new StopWatch("统一一组任务耗时");
        stopWatch.start("任务一");
        int [] arr = {3, 2, 67, 5, 4, 1, 9,232,434,545,6776,879,23,5678,9898,56321,344568,2343};
        SelectSort (arr);
        System.out.println(JSON.toJSONString(arr));
        // 统计任务一耗时
        Thread.sleep(1000);
        stopWatch.stop();
        String result = stopWatch.prettyPrint();
        System.err.println(result);

    }
    //简单选额排序
    private static void SelectSort (int [] arr) {
        int min, temp, tempIndex;			//最小值,交换中间值,每轮换得的最小值索引
        for (int i = 0; i < arr.length; i++) {
            min = arr [i];
            tempIndex = i;
            for (int j = i + 1; j < arr.length; j++) {				//比较得到最小值和其索引值
                if (arr [j] < min) {
                    min = arr [j];
                    tempIndex = j;
                }
            }
            //交换
            temp = arr [i];
            arr [i] = arr [tempIndex];
            arr [tempIndex] = temp;
        }
    }

运行后的效果

StopWatch '统一一组任务耗时': running time (millis) = 1122
-----------------------------------------
ms     %     Task name
-----------------------------------------
01122  100%  任务一
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值