that is a normal empty loop with a normal increment operator "i++"
import Foundation
let start = CFAbsoluteTimeGetCurrent()
for var i = 0; i < 1000000; i++ {
}
let timeTaken = CFAbsoluteTimeGetCurrent() - start
println(timeTaken) // 0.0229730010032654
but this loop 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) // 0.00384700298309326
the second loop is 5x - 6x times faster
i understand swift is still in beta and i don't compare it to other languages but that makes no sense for me
isnt that a optimizer problem? a fair test world be
var i = 0
for j in 1..1000000 {
i++
}
var i = 0
for j in 1..1000000 {
i = i + 1
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With