Re:Rust is now overall faster than C in benchmarks
by zarkov99 on Sunday January 03, 2021 @02:27PM
(#25624351)
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.
[ Parent
| on HN ]
Re:Rust is now overall faster than C in benchmarks
by gpderetta on Sunday January 03, 2021 @02:33PM
(#25624408)
Technically 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.
Re:Rust is now overall faster than C in benchmarks
by rurban on Sunday January 03, 2021 @05:45PM
(#25625956)
Don'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.