https://github.com/ly0va/sort-bench
Sorting benchmarks of compiled languages
https://github.com/ly0va/sort-bench
benchmark cpp golang mergesort rust
Last synced: 7 months ago
JSON representation
Sorting benchmarks of compiled languages
- Host: GitHub
- URL: https://github.com/ly0va/sort-bench
- Owner: ly0va
- License: mit
- Created: 2020-03-27T18:16:45.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2022-06-07T10:00:27.000Z (over 3 years ago)
- Last Synced: 2025-01-22T19:14:17.911Z (9 months ago)
- Topics: benchmark, cpp, golang, mergesort, rust
- Language: Jupyter Notebook
- Homepage:
- Size: 58.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Sorting Benchmarks
These are speed benchmarks of merge sort algorithm implemented in Rust, C++ and Go.
The goal was to compare speed and efficiency of optimizations done by 3 most popular compiled
languages. The algorithm implementations in all 3 languages are kept as similar as possible by the means of said languages.
As a reference point, results are compared to those of the built-in sort versions (which, however, implement algorithms other than merge sort).## Installation
Dependencies:
- GNU Make
- GNU g++
- libpthread
- openmp
- rust suite (cargo, rustc, etc.)
- go```bash
git clone https://github.com/ly0va/sort-bench.git
cd sort-bench
make
```## Results
**Benchmark setup:**
1. Each configuration was ran 25 times (to reduce the error) against an array of 100 million `int`s.
2. For each language, arrays are generated randomly, with a fixed seed.
3. Sequential fallback was implemented, meaning that parallel implementations use sequential ones, once array size is small enough, 213 here.
Without it, programs take much, MUCH longer to finish (since they spawn so many threads), and in the case of Go, freeze my computer and do not finish at all.4. CPU: Intel i5-3320M (4 cores) @ 3.3GHz
5. OS: Arch Linux (kernel version 5.5)
| Implementation | C++ | Rust | Go |
| --- | --- | --- | --- |
| Single-threaded | 16.16s | 20.12s | 20.69s |
| Multi-threaded | 9.86s | 10.34s | 10.00s |
| Built-in | 9.00s | 8.82s | 30.29s |
| Built-in parallel | 3.21s | 4.25s | -- |
## Conclusions
1. Go's built-in sort is weirdly slow.
2. If not using Go, you are better off with a built-in implementation.
3. It is good to utilize all of your cores.
4. Unfortunately, sequential fallbacks are still necessary everywhere.