4 ms·
In he case of std::sort the C++ compiler can inline the comparison function when it generates the actual sort implementation from the std::sort template. In C t
by zarkov99 6y ago
In he case of std::sort the C++ compiler can inline the comparison function when it generates the actual sort implementation from the std::sort template. In C the qsort implementation is fixed and must call the comparison via an indirect reference.
- rurban 6y agoDon't use a libc qsort then. The compiler could generated it (but they don't even generate optimized memcmp yet). Or the CTL is a header only STL for C, which inlines the sort function and the comparator. And because of the C++ bloat and indirect calls the C version is faster. Inlining with macros == constexpr with templates. You can decide which syntax you prefer.
- gpderetta 6y agoTechnically libc couldhave an inline version of qsort in the header or the linker (even the dynamic linker) could do LTO, but bechmarks are done on actual implementations not the mythical sufficiently good compiler.