which is a regular empty loop with the normal increment operator "i ++"
import Foundation let start = CFAbsoluteTimeGetCurrent() for var i = 0; i < 1000000; i++ { } let timeTaken = CFAbsoluteTimeGetCurrent() - start println(timeTaken)
but this cycle with "i = i + 1" is much faster
import Foundation let start = CFAbsoluteTimeGetCurrent() for var i = 0; i < 1000000; i = i + 1 { } let timeTaken = CFAbsoluteTimeGetCurrent() - start println(timeTaken)
the second cycle is 5x - 6 times faster
I understand that swift is still in beta, and I do not compare it with other languages, but for me it does not make sense.
source share