Created
July 22, 2013 03:50
-
-
Save vaskoz/6051195 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Arrays; | |
import java.time.*; | |
public class PSort { | |
public static void main(String[] args) { | |
if (args.length != 2) { | |
System.err.println("Usage: PSort [seq|par] [data size int]"); | |
System.exit(1); | |
} | |
boolean parallel = "par".equals(args[0]); | |
int DATA_SIZE = Integer.valueOf(args[1]); | |
int[] data = new int[DATA_SIZE]; | |
for (int i = 0; i < data.length; i++) | |
data[i] = (int)(Math.random() * Integer.MAX_VALUE); | |
LocalDateTime start = LocalDateTime.now(); | |
if (parallel) Arrays.parallelSort(data); | |
else Arrays.sort(data); | |
System.out.println("Finished in: " + Duration.between(start, LocalDateTime.now()).toMillis()); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
java PSort | |
Usage: PSort [seq|par] [data size int] | |
# 100,000,000 = 100 MILLION - Parallel Sorting Wins | |
java -Xms2g -Xmx2g PSort seq 100000000 | |
Finished in: 10567 | |
java -Xms2g -Xmx2g PSort par 100000000 | |
Finished in: 4622 | |
# 10 MILLION - Parallel Sorting Wins | |
java -Xms2g -Xmx2g PSort seq 10000000 | |
Finished in: 954 | |
java -Xms2g -Xmx2g PSort par 10000000 | |
Finished in: 595 | |
# 500k - Sequential Sorting Wins | |
java -Xms2g -Xmx2g PSort seq 500000 | |
Finished in: 131 | |
java -Xms2g -Xmx2g PSort par 500000 | |
Finished in: 180 | |
# 1 MILLION - Sequential Sorting Wins. | |
java -Xms2g -Xmx2g PSort seq 1000000 | |
Finished in: 170 | |
java -Xms2g -Xmx2g PSort par 1000000 | |
Finished in: 216 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment