Skip to content

A framework for benchmarking sorting algorithms

Notifications You must be signed in to change notification settings

ThatOtherAndrew/Complexity

Folders and files

NameName
Last commit message
Last commit date

Latest commit

12ab4ec · · Nov 24, 2025

History

30 Commits
Nov 24, 2025
Nov 19, 2025
Nov 20, 2025
Nov 19, 2025
Nov 19, 2025
Nov 19, 2025
Nov 21, 2025
Nov 24, 2025
Nov 8, 2025
Nov 19, 2025
Nov 19, 2025
Nov 20, 2025
Nov 21, 2025
Nov 21, 2025
Nov 20, 2025

Repository files navigation

The Complexity Project

The Complexity Project is a framework for benchmarking various sorting algorithms and inspecting their time complexity. (If you've ever seen those social media videos of bars of varying heights being sorted and making funny noises, that's what this is about!)

Current features include:

  • Dynamic iteration count, to balance between benchmark duration and accuracy
  • A benchmark warm-up phase to reduce bias from initial overhead ("cold start")
  • Different initial sorting conditions: sorted, reverse sorted, and random
  • Example data analysis and visualisation in a Jupyter notebook
  • Three custom sorting algorithm implementations of selection sort, quicksort, and merge sort
  • An abstract base class for implementation of additional sorting algorithms
  • An automated unit test and fuzz test suite to validate your custom sorting algorithms

Usage instructions

Ensure you have a JDK installed, then clone the repository:

git clone https;//github.com/ThatOtherAndrew/Complexity

cd Complexity

Optionally, add your custom sorting algorithms in the src/sorters directory. A template is provided below:

package sorters;


public class MySpecialSorter extends Sorter {
     public BuiltinSorter(int[] unsortedArray) {
         super(unsortedArray);
    }

       @Override
     public void sort(int[] array) {
         // Implement your sorting algorithm here!!
    }
}
}

No reflection is implemented, so the new sorting algorithm will have to be manually added to src/Main.java:

runAndRecordBenchmark(writer, "MySpecialSort", size, condition, new MySpecialSorter(testArray));

Then, compile the source code and run the benchmark with the following command!

javac -d out -sourcepath src src/Main.java
java -Xss10m -cp out Mainn

The resulting data will be output to benchmark_results.csv, ready for further analysis. (Be warned, this file can grow very large very quickly!)

Example data analysis

An example Jupyter notebook is provided as Complexity.ipynb. Below are some of the graphs generated from the benchmark data:

Scatter plot of execution times

Scatter plot of execution times

Line plot of different initial sorting conditions

Line plot of different initial sorting conditions

Log-log plot demonstrating time complexity classes

Log-log plot demonstrating time complexity classes

About

A framework for benchmarking sorting algorithms

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published