Note that there are some explanatory texts on larger screens.

plurals
  1. POArrays sort vs parallelSort performance comparision
    primarykey
    data
    text
    <h2><strong>I've downloaded <code>java8-ea</code> release and did a fast comparison between <code>Array.sort</code> and <code>Arrays.parallelSort</code>.</strong></h2> <p>And this was the result: <img src="https://i.stack.imgur.com/x3088.jpg" alt="enter image description here"></p> <p>I can understand that the praralleSort should perform at least as Plain old <code>sort</code>, if not faster.. but this is not what happened.</p> <h2><strong>The Comparison done on the following specs:</strong></h2> <p>HP ProBook <code>Intel Core i5</code> with <code>4G RAM</code> on <code>Ubuntu 13.04 Linux</code> with JDK of version: <code>Java HotSpot(TM) 64-Bit Server VM (build 25.0-b23, mixed mode)</code></p> <h3><strong>I've created an array of Custom object of three fields by this way (add object in reserve order):</strong></h3> <pre><code>package com.cmd; import java.util.Arrays; public class Main { public static void main(String[] args) { for (int i=100; i &lt;= 10_000_000; i*=10){ runTest(i); } } private static void runTest(final int size){ // Fist obtain two Arrays of same data Employee[] empArrForSort = createVeryLargeEmpArray(size); Employee[] empArrForSortCopy = Arrays.copyOf(empArrForSort, empArrForSort.length); long start = System.currentTimeMillis(); Arrays.sort(empArrForSort, (e1, e2) -&gt; new Integer(e1.getId()).compareTo(e2.getId())); logStart(size + ": sort", start); start = System.currentTimeMillis(); Arrays.parallelSort(empArrForSortCopy, (e1, e2) -&gt; new Integer(e1.getId()).compareTo(e2.getId())); logStart(size + ": parallel sort", start); } private static void logStart(String label, long startTimeMillis) { System.out.println("End " + label + " the array. It took: " + (System.currentTimeMillis() - startTimeMillis) + " ms"); } private static Employee[] createVeryLargeEmpArray(final int size) { Employee[] ret = new Employee[size]; for (int i = 0; i &lt; ret.length; i++) { ret[i] = Employee.createEmployee(ret.length - i, "Mohammad" + i, ""); } return ret; } static class Employee { private int id; private String name; private String email; private Employee(int id, String name, String email) { this.id = id; this.name = name; this.email = email; } public static Employee createEmployee(int id, String name, String email) { return new Employee(id, name, email); } public int getId() { return id; } } } </code></pre> <p>And, Another run shows that, Parallel only perform pad when the list contains 10,000,000, in all other cases it looks better. </p> <pre><code>&gt;java -Xmx2000m com.cmd.Main End 100: sort the array. It took: 110 ms End 100: parallel sort the array. It took: 6 ms End 1000: sort the array. It took: 2 ms End 1000: parallel sort the array. It took: 3 ms End 10000: sort the array. It took: 11 ms End 10000: parallel sort the array. It took: 11 ms End 100000: sort the array. It took: 15 ms End 100000: parallel sort the array. It took: 37 ms End 1000000: sort the array. It took: 553 ms End 1000000: parallel sort the array. It took: 187 ms End 10000000: sort the array. It took: 640 ms End 10000000: parallel sort the array. It took: 1099 ms </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload