2 ms·
C++ can inline the comparison function (which is often just a few instructions) at compile time. It can also statically optimize for the stride, using shifts or
by tlb 6y ago
C++ can inline the comparison function (which is often just a few instructions) at compile time. It can also statically optimize for the stride, using shifts or addressing modes instead of multiplies. C can't do either with qsort, which takes the stride and comparison function pointer as arguments.
- makapuf 6y agoUnless comparison function is small and can be inlined, which would trigger the same stride shift optimizations.