Re: qsort_b in Swift


On Sep 16, 2017, at 8:40 PM, Gerriet M. Denkmann <g@...> wrote:

This is the first time I have seen Swift working swifter than Objective-C (and not by a small margin too!).
I am very impressed with the Swift sort.
It would be interesting to know what kind of optimisation magic Swift does here.

The compiler probably inlines the call to the comparison function, as opposed to qsort_b which has (of course) already been compiled so it has to make a regular function call. That makes a big difference when the function is as cheap as comparing two integers.

Similarly, in the Swift code the size of the array elements is a compile-time constant, whereas to qsort_b it's a variable. That results in more efficient code.


Join to automatically receive all group messages.