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.
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...