Skip to content

A collection of sorting algorithms and a simple benchmark program

License

Notifications You must be signed in to change notification settings

rswinkle/sorting

Repository files navigation

Sorting Algorithms

Run on Repl.it

This is just a set of sorting algorithms and a benchmarking program.

I should add several more sorting algorithms and have a cleaner divided system for testing sets of algorithms with different Big-O running times.

I realize that clock() isn't the most accurate/precise timing method but it's simple to use and will result in the same ranking even if those numbers aren't actually milliseconds.

"The clock() function returns the processor time since the program started, or - 1 if that information is unavailable. To convert the return value to seconds, divide it by CLOCKS_PER_SEC. (Note: if your compiler is POSIX compliant, then CLOCKS_PER_SEC is always defined as 1000000.) "

Building and Running

You can use the included makefile:

cd build
make
./benchmark

Or you can regenerate it or another build system using premake5

premake5 gmake
cd build
make
./benchmark

There's benchmark is the main C program that I usually update and test with new algorithms and cppbenchmark which I only occasionally use, mostly just to make sure everything still compiles and runs the same as C++.

The results are pretty self explanatory but you can redirect them to a file (output.dat) and then run plotbarchart.py to get a "nice" bar chart of the data. See heapsort_times.png and quicksort_times.png for old examples.

Algorithms

  • Quicksort and 3 variations
  • Heap sort and 2 variations
  • Merge sort and 1 variation
  • Insertion sort
  • Radix sort
  • Shell sort
  • Comb sort
  • Gnome Sort, Bubble Sort, etc.