如何测试代码执行时间

插曲(测试代码执行时间)

Math.random() 可以生成随机数
random实例的nextInt(), nextDouble() 也可以。

    /**
     *  测试八万的数据
     */
    public static void costTime() {
        int[] arrays3 = new int[80000];
        Random random2 = new Random();
        for (int i = 0; i < arrays3.length; i++) {
            arrays3[i] = random2.nextInt(80000);
        }
        long startTime = System.currentTimeMillis();
        //quickSort(arrays3,0, arrays3.length-1);   // 正规的插入,有值的后移
      	xxx // your code here . 
        long endTime = System.currentTimeMillis();
        System.out.println("程序运行时间优化时间为:" + (endTime - startTime)*0.001 + "s"); //输出程序运行时间
    }
原文地址:https://www.cnblogs.com/hujesse4/p/15323868.html