https://github.com/dietime/qqsort
Reimplementation of qsort function from glibc with more ability to inline comparison function.
https://github.com/dietime/qqsort
Last synced: 10 months ago
JSON representation
Reimplementation of qsort function from glibc with more ability to inline comparison function.
- Host: GitHub
- URL: https://github.com/dietime/qqsort
- Owner: DieTime
- License: mit
- Created: 2023-08-18T20:35:35.000Z (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2023-08-20T11:10:30.000Z (almost 3 years ago)
- Last Synced: 2025-06-23T16:38:47.099Z (12 months ago)
- Language: C++
- Homepage:
- Size: 55.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
The `qqsort` macro is a reimplementation of [qsort](https://codebrowser.dev/glibc/glibc/stdlib/qsort.c.html) function from glibc with more ability to inline comparison function.
# Usage
```c
#include
#include "qqsort.h"
int main(void) {
int array[] = {4, 3, 2, 1, 0, 5, 6, 7, 8, 9};
int size = sizeof(array) / sizeof(array[0]);
qqsort(array,
size,
sizeof(int),
qqsortcmp(int *a, int *b) {
qqsortret(*a - *b);
});
for (int idx = 0; idx < size; idx++) {
printf("%d ", array[idx]);
}
return 0;
}
```
# Benchmark
> ❗This project is just an experiment to study the influence of inlining on code performance.
Machine used for benchmark:
* AMD Ryzen 7 5800x
* 16GB RAM
* Linux 6.2.0
For the benchmark, a simple C++ [program](./benchmark/main.cpp) was implemented to sort an array of structures in three ways:
* Sorting using `stl`
* Sorting using the `qsort` function of the library
* Sorting with the `qqsort` macro
Three compilers were used to build the benchmark:
* `g++ 11.4.0`
* `clang++ 14.0.0`
* `msvc 19.37`
The following compilation flags were used:
```python
COMPILE_ARGS = [ "-flto", "-O2", ... ]
```
The `qqsort` macro showed positive results in performance only when using the `g++` and `msvc` compilers. When using `clang++`, the `qqsort` macro performs worse than the `qsort` function.


