Merge Sort - Performance

This section provides a tutorial on how to measure the performance of the Merge Sort algorithm. My first Java implementation of Merge Sort is performing somewhere between O(N*Log2(N) and O(N*N) order levels.

Now let's see how my Java implementation of the Merge Sort algorithm performs. I tried this implementation with my SortTest.java under JDK 1.3.1. Here are the results:

Array size: 10000
Average sorting time: 98 milliseconds
Number of tests: 1000
Performance: 9.8 O(N) nanoseconds
Performance: 0.7375234893767539 O(N*Log2(N)) nanoseconds
Performance: 9.8E-4 O(N*N) nanoseconds

Array size: 20000
Average sorting time: 222 milliseconds
Number of tests: 1000
Performance: 11.1 O(N) nanoseconds
Performance: 0.7768913388743642 O(N*Log2(N)) nanoseconds
Performance: 5.55E-4 O(N*N) nanoseconds

Array size: 30000
Average sorting time: 336 milliseconds
Number of tests: 1000
Performance: 11.2 O(N) nanoseconds
Performance: 0.753058887534575 O(N*Log2(N)) nanoseconds
Performance: 3.733333333333333E-4 O(N*N) nanoseconds

The performance of this implementation is at the order of O(N*Log2(N)). But it is about 5 times slower than java.util.Arrays.sort().

Last update: 2011.

Table of Contents

 About This Book

 Introduction of Sorting Algorithms

 Java API for Sorting Algorithms

 Insertion Sort Algorithm and Implementation

 Selection Sort Algorithm and Implementation

 Bubble Sort Algorithm and Implementation

 Quicksort Algorithm and Implementation

Merge Sort Algorithm and Implementation

 Merge Sort - Algorithm Introduction

 Merge Sort - Java Implementation

Merge Sort - Performance

 Merge Sort - Implementation Improvements

 Heap Sort Algorithm and Implementation

 Shell Sort Algorithm and Implementation

 Performance Summary of Java Implementations

 References

 PDF Printing Version