Git Product home page Git Product logo

qqsort's Introduction

License: BSD 3-Clause Usage Single Header

The qqsort macro is a reimplementation of qsort function from glibc with more ability to inline comparison function.

Usage

#include <stdio.h>
#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 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:

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.

benchmark-g++ benchmark-msvc benchmark-clang++

qqsort's People

Contributors

dietime avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.