整数数组集合的基准排序算法

问题描述

我正在对一组数组上的一些流行排序算法进行非常基本的基准测试。我想将它们存储在一个列表中(也许是个坏主意)并返回使用纳秒差异对数组进行排序所需的时间。我快到了,但我知道我正在返回迭代器每次迭代的累积总时间,而不仅仅是最后的总时间。我确实得到了最后的总时间,但我有点困惑如何只获得总时间输出

public static void main(String[] args) {
    makeArray(100,50);  //make 100 arrays at size 50
    System.out.println();
        BubbleSort bs = new BubbleSort();    //Create bs obj
    for (Iterator<int[]> iterator = listofArrays.iterator(); iterator.hasNext();) {
        int[] isSort = (int[]) iterator.next();
        double time =(bs.benchmark(isSort));  //pass iterators arrays to benchmark method
        System.out.println("Total time: " + time);
    }//rof
}//main

在我的 runner 类 main 方法中,我创建了一些数组,将它们添加到静态 ArrayList(可能也是一个坏主意)并通过迭代器将它们传递给我下面的基准测试方法,然后依次对数组进行排序。

public double benchmark(int[] toSort){
    double startTime = System.nanoTime();
    bubble(toSort);
    double endTime = System.nanoTime();
    double timeElapsed = endTime - startTime ;
    double elapsedMillis = timeElapsed/1000000;
    total+=elapsedMillis;  //total is a static class variable but this isnt viable longterm imo
    return total;  //this is returned after each array in the collection is sorted obvIoUsly
}//benchmark

我理解它有点乱,它只是一个粗略的初稿,但我只是需要朝着正确的方向努力。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)