阵列排序与并行排序性能比较 我下载了java8ea发行版,并对Array.sort和Array.parallelSort进行了快速比较

阵列排序与并行排序性能比较 我下载了java8ea发行版,并对Array.sort和Array.parallelSort进行了快速比较,java,parallel-processing,java-8,Java,Parallel Processing,Java 8,结果是: 我可以理解praralleSort应该至少执行普通的排序,如果不是更快的话。。但事实并非如此 对以下规格进行比较: HP ProBookIntel Core i5在Ubuntu13.04 Linux上安装4G RAM,JDK版本为:Java HotSpot(TM)64位服务器虚拟机(构建25.0-b23,混合模式) 我用这种方法创建了一个包含三个字段的自定义对象数组(按保留顺序添加对象): 这里的要点是,数组按相反顺序排序。 这是一个非常独特的场景,并不意味着算法的总体性能。 我运行

结果是:

我可以理解praralleSort应该至少执行普通的
排序
,如果不是更快的话。。但事实并非如此

对以下规格进行比较: HP ProBook
Intel Core i5
Ubuntu13.04 Linux上安装
4G RAM
,JDK版本为:
Java HotSpot(TM)64位服务器虚拟机(构建25.0-b23,混合模式)

我用这种方法创建了一个包含三个字段的自定义对象数组(按保留顺序添加对象):
这里的要点是,数组按相反顺序排序。 这是一个非常独特的场景,并不意味着算法的总体性能。 我运行了相同的代码,但使用了无序数组:

  ret[i] = Employee.createEmployee(rnd.nextInt(ret.length), "Mohammad" + i, "");
结果表明,与反向排序相比,并行排序的性能要慢得多,而并行排序的速度要快得多

End 100: sort the array. It took: 139 ms
End 100: parallel sort the array. It took: 4 ms
End 1000: sort the array. It took: 4 ms
End 1000: parallel sort the array. It took: 6 ms
End 10000: sort the array. It took: 35 ms
End 10000: parallel sort the array. It took: 30 ms
End 100000: sort the array. It took: 420 ms
End 100000: parallel sort the array. It took: 144 ms
End 1000000: sort the array. It took: 1341 ms
End 1000000: parallel sort the array. It took: 506 ms
End 10000000: sort the array. It took: 12200 ms
End 10000000: parallel sort the array. It took: 3971 ms

我已经创建了许多测试,在大多数情况下,并行排序的性能比(串行)排序要好得多。

createverylargeemarray
方法中只修改了2行,如下所示

Random random = new Random();
ret[i] = Employee.createEmployee(ret.length - i+random.nextInt(size), "Mohammad" + i, "");
以下是结果 结束100:对数组进行排序。耗时:27毫秒
End 100:对数组进行并行排序。时间:1毫秒

结束1000:对数组进行排序。耗时:1毫秒
End 1000:对数组进行并行排序。时间:1毫秒

End 10000:对数组进行排序。耗时:7毫秒
End 10000:对数组进行并行排序。耗时:145毫秒

End 100000:对数组进行排序。耗时:105毫秒
End 100000:对数组进行并行排序。时间:59毫秒

End 1000000:对数组进行排序。耗时:1050毫秒
End 1000000:对数组进行并行排序。时间:194毫秒

结束10000000:对数组进行排序。耗时:12636毫秒
End 10000000:对数组进行并行排序。时间:2107毫秒


随着未排序元素数量的增加,并行排序的性能开始比常规排序好得多。

您的问题是什么?您的系统中有多少内核?我不确定,但我有一个Intel Core i5 second Gen。我喜欢您添加的。请提供一些测试数据,或者大多数用户会认为您的答案无效/不完整;)还有,欢迎来到SO!
End 100: sort the array. It took: 139 ms
End 100: parallel sort the array. It took: 4 ms
End 1000: sort the array. It took: 4 ms
End 1000: parallel sort the array. It took: 6 ms
End 10000: sort the array. It took: 35 ms
End 10000: parallel sort the array. It took: 30 ms
End 100000: sort the array. It took: 420 ms
End 100000: parallel sort the array. It took: 144 ms
End 1000000: sort the array. It took: 1341 ms
End 1000000: parallel sort the array. It took: 506 ms
End 10000000: sort the array. It took: 12200 ms
End 10000000: parallel sort the array. It took: 3971 ms
Random random = new Random();
ret[i] = Employee.createEmployee(ret.length - i+random.nextInt(size), "Mohammad" + i, "");