Bubble Sort - Performance

This section provides a tutorial on how to measure the performance of the Bubble Sort algorithm. My first Java implementation of Bubble Sort is performing at the O(N*N) order level.

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

Array size: 1000
Average sorting time: 53 milliseconds
Number of tests: 1000
Performance: 53.0 O(N) nanoseconds
Performance: 5.318196590063668 O(N*Log2(N)) nanoseconds
Performance: 0.053 O(N*N) nanoseconds

Array size: 2000
Average sorting time: 217 milliseconds
Number of tests: 1000
Performance: 108.5 O(N) nanoseconds
Performance: 9.89441312937002 O(N*Log2(N)) nanoseconds
Performance: 0.05425 O(N*N) nanoseconds

Array size: 3000
Average sorting time: 488 milliseconds
Number of tests: 1000
Performance: 162.66666666666666 O(N) nanoseconds
Performance: 14.082783536776278 O(N*Log2(N)) nanoseconds
Performance: 0.05422222222222222 O(N*N) nanoseconds

Obviously, this is the worst performed sorting implementation so far, with 0.054 O(N*N).

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

 Bubble Sort - Algorithm Introduction

 Bubble Sort - Java Implementation

Bubble Sort - Performance

 Bubble Sort - Implementation Improvements

 Quicksort Algorithm and Implementation

 Merge Sort Algorithm and Implementation

 Heap Sort Algorithm and Implementation

 Shell Sort Algorithm and Implementation

 Performance Summary of Java Implementations

 References

 PDF Printing Version