Re:Linus Torvalds on C++
by cageface on Tuesday February 28, 2012 @04:17AM
(#3642510)
C++ can actually be faster because it doesn't throw away as much type information. A good, typed C++ quicksort implementation, for example, will be faster than a C version using void*.
[ Parent
| on HN ]
One of the reasons for the performance difference is that you can't inline into the libc DLL blob: If you use qsort(), you'll get a lot of overhead from calling the comparison function.
If you use a custom quicksort implementation and put it into the same translation unit as the comparison function (or compile statically and use link-time optimizations with a sufficiently advanced compiler) you can get the same performance out of C.
Function call overhead is only one of the issues with the C version based on void pointers.
Check out Stroustrup's keynote at Going Native 2012 for more details: http://channel9.msdn.com/Events/GoingNative/GoingNative-2012...