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
Ensure you have a JDK installed, then clone the repository:
git clone https;//github.com/ThatOtherAndrew/Complexity
cd ComplexityOptionally, 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 MainnThe resulting data will be output to benchmark_results.csv, ready for further analysis. (Be warned, this file can grow very large very quickly!)
An example Jupyter notebook is provided as Complexity.ipynb. Below are some of the graphs generated from the benchmark data: