

Apples to Apples, Part II - poolpool
http://www.jessesquires.com/apples-to-apples-part-two/

======
mpweiher
Looking at the original article, it seems like he is comparing sorting an
array of NSNumber _objects_ in Objective-C with sorting an array of
_primitive_ integers in Swift.

The only really big surprise is that the latter actually used to be _slower_.
Boggle.

~~~
JonathonW
It's worth noting that Swift Ints (and Arrays) aren't primitives; they're
named types defined as structs in Swift code in the standard library, and have
methods and can be extended like any other types in the library (see [1]).
That's why the unoptimized case is slow, and why the author gets such a
dramatic speedup from optimization-- the Swift optimizer (unlike the Objective
C optimizer, which, thanks to ObjC's messaging system, has to keep method
calls intact) can use techniques like method inlining to bring performance to
a point close to that of a native int/plain C array.

Regardless, I'd still like to see a comparison with C++ (where method dispatch
looks a lot like Swift and the optimizer should be able to do similar things)
and plain C. Might have to try that this evening if I get bored.

1:
[https://developer.apple.com/library/prerelease/mac/documenta...](https://developer.apple.com/library/prerelease/mac/documentation/Swift/Conceptual/Swift_Programming_Language/Types.html#//apple_ref/doc/uid/TP40014097-CH31-XID_1078)

~~~
coob
Likewise, it's also worth noting that since 10.7/iOS 5, NSNumbers can be
tagged pointers rather than separately allocated objects.

------
ljosa
Expected an Apple II; was disappointed.

