This Repo shows different sorting algorithms implemented in Golang.
Every sorting algorithm is packed into its own folder and loaded into main. I also created a benchmark file.
Don't run the entire file at once, it will fail due to the 11 minutes limit.
The main package does implement call for every package that in this module:
- Array of, 100000 random integers between 0 and 9223372036854775807 (
math.MaxInt
) - Copy the created array, run Insertion Sort and measure the time it takes to sort the array
- Copy the created array, run Bubble Sort and measure the time it takes to sort the array
- Copy the created array, run Shell Sort and measure the time it takes to sort the array
- Copy the created array, run Quick Sort and measure the time it takes to sort the array
- Copy the created array, run Merge Sort and measure the time it takes to sort the array
- Copy the created array, run the sorting algorithm build into go sort (from
sort pkg
) and measure the time it takes to sort the array - Copy the created array, run Slice Sort (from
golang.org/x/exp/slices
) and measure the time it takes to sort the array
The benchmark file ./main_test.go
does the same, but run with the input cases:
Warning
For some sorting algorithms It's impossible to get a successful run (e.g. Bubble Sort)!
- 10
- 100
- 1000
- 10000
- 100000
- 1000000
- 10000000
- 100000000
Under the intense scrutiny of unit tests, each sorting algorithm unveils its intricate dance. The way they align, correct and reorder data โ it's like a performer on a stage, demonstrating their meticulously rehearsed act. Each test is a critical audience, assessing the show and ensuring that the performance is flawless. Change the routine? The unit tests won't miss any missteps. Adapting this practice transforms your routine code into a dynamic spectacle, elegantly flowing in the theater of your software. In turn, every line of code is now part of a thrilling performance, each playing a pivotal role in keeping the audience, which is your software system, captivated.
You can run this Repo in Codesandbox!
go run cmd/go-sort/main.go
go test -v tests/main_test.go
go test -bench=. tests/main_test.go