Quote:
I am not convinced of Scott Meyers's claim that his test result show std::sort faster than qsort() by 670%. Show me the code. Paul tried to show me once how std::sort() can sort as fast as qsort, but his example failed him miserably by showing a speed many orders of magnitude slower.
OK, not 670% - I concede defeat on that, since my system is obviously not the same a Scott Meyers'. But 410% is still pretty impressive.
Quote:
The swap function used by qsort swaps object one byte at a time, while as std::sort has the benefit of compiler optimization and swaps things at least 4 times faster (a 4 bytes integer at a time). So indeed qsort is bad in this aspect.
So how do you propose to improve qsort's swapping? One of the arguments we've used against qsort is its lack of type-safety. It's that lack that is directly responsible for its inefficiency in swapping. I would hope that any half-decent std::sort implementation would use std::swap to swap objects, because then I can specialise swap for my class and make it efficient. You can swap two vectors (of any size) in the time it takes to swap two pointers: you can tell std::sort that, but you can't tell qsort.
These factors are not annoying little details that help to explain away an inconvenient result - they are fundamental reasons why std::sort is preferable to qsort.
Quote:
But the fact still remains that Scott Meyers is WRONG in asserting that inlining makes std::sort faster. I dumped both the release version and debug version compiled code to assembly. Guess what:
Not a single inline function is being actually inlined.
And just think, if the compiler did inline those functions, just how embarrasing the comparison would be then.
Quote:
In Graham's code, the two comparison function use are not equivalent in code complexity. So it is not quote a fair comparison.
Don't talk tosh. I tried to make the two functions of equivalent complexity. That I couldn't is entirely down to qsort's requirements on the function (the need for void* arguments and a three-valued result). Don't tell me it's not fair, both functions were as efficient as the constraints allowed - it's another fundamental factor in the comparison: std::sort allows you to to use less complex comparison functions.
Quote:
std::sort() wins this battle over qsort purely by the fault of qsort author not being able to write something that copies more than a byte at a time.
Cobblers. It's not the author's fault - he's hamstrung by the nature of qsort.
Quote:
It also thanks to the fact that the object less<int> Graham used is an empty object, and hence passing it is never a huzzle.
And the original functor I proposed (and that you objected so strongly to) is also an empty object. That's another factor: any predicate should be an empty object.