This Repo shows different search algorithms implemented in Golang.
Every search algorithm is packed into its own folder and loaded into main. I also created a benchmark file.
The main package does implement call for every package that in this module:
- create an Array of 100000 random integers between 0 and 9223372036854775807 (
math.MaxInt
) - run linear search and measure the time it takes to search through the array
- sort the array and run binary search and measure the time it takes to search through array
- sort the array and run binary search with concurrency and measure the time it takes to sort the array
- sort the array and run interpolation search and measure the time it takes to search through array
- sort the array with concurrency and run interpolation search and measure the time it takes to search through array
The benchmark file tests/main_test.go
does the same, but run with the input cases:
- 10
- 100
- 1000
- 10000
- 100000
- 1000000
- 10000000
- 100000000
Under the intense scrutiny of unit tests, each search 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-search/main.go
go test -v tests/main_test.go
go test -bench=. tests/main_test.go