Skip to content

Sorting Comparison: Go vs Java

March 15, 2014

Sorting is probably the most common operation done by computers throughout their entire history. As a Java/JVM developer, I thought I’d do a quick benchmark to compare Java and Go’s sorting standard library algorithms by sorting ONE BILLION integers.

Both Java’s java.util.Arrays.sort(int[]) and Go’s sort.Ints([]int) use a version of Quicksort as their implementation. This benchmark just tests these two standard library implementations against each other. In the future I will implement a set of algorithms in both Java and Go and perform my own benchmarks for the exact same algorithm.

The “results.txt” file below contains the summary of the test results, but the spoiler is Java beat Go in sorting in all situations. Also, if we test using java.util.Arrays.parallelSort(int[])  into the comparison the test becomes even more lopsided. Java’s parallelSort uses a variation of merge sort which uses O(n) extra memory but performs X times faster where X is equal to the number of processing cores available.

Advertisements

From → Golang, Java

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: