Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Sorting Algorithm Benchmark

A C++ console program that implements and compares bubble sort, selection sort, insertion sort, and quicksort on the same randomly generated dataset.

Problem

Algorithm descriptions can feel abstract until their runtime differences are measured on identical input. This project makes those tradeoffs observable.

Solution

The program:

  • generates 50,000 random integers;
  • copies the original values before every benchmark;
  • times each algorithm with std::chrono;
  • prints the results to the console; and
  • writes the same results to output.txt.

Technology

  • C++17
  • Standard library timing and file streams
  • Visual Studio-compatible source files

Setup

g++ -std=c++17 -O2 main.cpp sort.cpp -o sorting-benchmark
./sorting-benchmark

Sample results

Benchmark results

One run on 50,000 integers produced:

Algorithm Time
Bubble sort 7,390 ms
Selection sort 4,268 ms
Insertion sort 743 ms
Quicksort 6 ms

Exact times vary by machine and random input. The important result is the scale of the difference between the quadratic algorithms and quicksort.

Challenges solved

  • Ensured every algorithm receives the same unsorted input.
  • Used static arrays to avoid stack pressure at the selected data size.
  • Separated the algorithms into a header and implementation file.
  • Recorded reproducible evidence in a human-readable output file.

Lessons learned

Implementation details and input distribution matter, but algorithmic complexity dominates as the dataset grows. Benchmark design also matters: comparing different input arrays would make the results less trustworthy.

Files

  • main.cpp — dataset creation, timing, output
  • sort.cpp — four algorithm implementations
  • sort.h — public function declarations
  • output.txt — sample benchmark run

About

C++ benchmark comparing Bubble, Selection, Insertion, and Quick sort on the same randomized dataset.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages