小编lch*_*a26的帖子

Java:使用System.nanoTime()排序函数执行时间太长

我试图获得不同数组大小的各种排序方法的总耗用时间.我能够获得size = 100,1000,10000和100000的经过时间,但是当我尝试1000000时它只是保持运行而不给出结果(我假设1000000太大了?).有没有办法使用nanoTime获取经过的时间,它会在合理的时间内编译?任何帮助都会很棒!

我的节目:

import java.util.Random;

public class Sorting {

public static void printArray(int[] array) {
    System.out.print("The Array: ");
    for (int i = 0; i < array.length; i++) {
        System.out.print(array[i] + " ");
    }
    System.out.println();
}

public static void exchange(int[] array, int i, int j) {
    int temp = array[i];
    array[i] = array[j];
    array[j] = temp;
}

public static void selectionSort(int[] array) {
    for (int fill = 0; fill < array.length - 2; fill++) {
        int minPos = fill;
        for …
Run Code Online (Sandbox Code Playgroud)

java sorting benchmarking bubble-sort nanotime

1
推荐指数
1
解决办法
583
查看次数

标签 统计

benchmarking ×1

bubble-sort ×1

java ×1

nanotime ×1

sorting ×1