Sorting Algorithm Tutorials - Herong's Tutorial Examples - 6.12, by Herong Yang
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. Here are the results with my SortTest.java class and HyArrays.bubbleSort() function using JDK 13.
Array size: 10000 Average sorting time: 284 milliseconds Number of tests: 1000 Performance: 28.4 O(N) microseconds Performance: 2.1373129692142663 O(N*Log2(N)) microseconds Performance: 0.00284 O(N*N) microseconds Array size: 20000 Average sorting time: 1383 milliseconds Number of tests: 1000 Performance: 69.15 O(N) microseconds Performance: 4.839823070555161 O(N*Log2(N)) microseconds Performance: 0.0034575 O(N*N) microseconds Array size: 30000 Average sorting time: 3297 milliseconds Number of tests: 1000 Performance: 109.9 O(N) microseconds Performance: 7.389390333933016 O(N*Log2(N)) microseconds Performance: 0.0036633333333333335 O(N*N) microseconds
Obviously, this is the worst performed sorting implementation so far, with 0.00284 O(N*N).
As a reference, results from an older computer are listed below:
Array size: 1000 Average sorting time: 53 milliseconds Number of tests: 1000 Performance: 53.0 O(N) microseconds Performance: 5.318196590063668 O(N*Log2(N)) microseconds Performance: 0.053 O(N*N) microseconds Array size: 2000 Average sorting time: 217 milliseconds Number of tests: 1000 Performance: 108.5 O(N) microseconds Performance: 9.89441312937002 O(N*Log2(N)) microseconds Performance: 0.05425 O(N*N) microseconds Array size: 3000 Average sorting time: 488 milliseconds Number of tests: 1000 Performance: 162.66666666666666 O(N) microseconds Performance: 14.082783536776278 O(N*Log2(N)) microseconds Performance: 0.05422222222222222 O(N*N) microseconds
Table of Contents
Introduction of Sorting Algorithms
Java API for Sorting Algorithms
Insertion Sort Algorithm and Java Implementation
Selection Sort Algorithm and Java Implementation
►Bubble Sort Algorithm and Java Implementation
Bubble Sort - Algorithm Introduction
Bubble Sort - Java Implementation
Bubble Sort - Implementation Improvements
Quicksort Algorithm and Java Implementation
Merge Sort Algorithm and Java Implementation
Heap Sort Algorithm and Java Implementation
Shell Sort Algorithm and Java Implementation
Sorting Algorithms Implementations in PHP
Sorting Algorithms Implementations in Perl
Sorting Algorithms Implementations in Python