Yes, what you did was interesting. But a bug report is even more useful.
Range evaluation seems to be the problem.
I added a loop with open range and surprisingly, loop is significantly faster:
Yields:
while duration 0.040472984313964844
for duration 6.2793790102005005
for duration open range 4.28174901008606
repeat duration 0.02440011501312256
I did post a bug report #FB8679385
Range evaluation seems to be the problem.
I added a loop with open range and surprisingly, loop is significantly faster:
Code Block var t = 0 var start = CFAbsoluteTimeGetCurrent() while t < 10_000_000 { t += 1 } print("while duration", CFAbsoluteTimeGetCurrent() - start) start = CFAbsoluteTimeGetCurrent() t = 0 for _ in 1...10_000_000 { // 10 mio iterations t += 1 } print("for duration", CFAbsoluteTimeGetCurrent() - start) start = CFAbsoluteTimeGetCurrent() t = 0 for _ in 1..<10_000_001 { // 10 mio iterations t += 1 } print("for duration open range", CFAbsoluteTimeGetCurrent() - start) start = CFAbsoluteTimeGetCurrent() t = 0 repeat { t += 1 } while t < 10_000_000 print("repeat duration", CFAbsoluteTimeGetCurrent() - start)
Yields:
while duration 0.040472984313964844
for duration 6.2793790102005005
for duration open range 4.28174901008606
repeat duration 0.02440011501312256
I did post a bug report #FB8679385