Created
September 29, 2019 01:39
-
-
Save rxwei/a8a50b9cbb09602f381cc8161f5fad4f to your computer and use it in GitHub Desktop.
Instruction count comparison
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@differentiable | |
func nested_loop(_ x: Float, count: Int) -> Float { | |
var outer = x | |
outerLoop: for _ in 1..<count { | |
outer = outer * x | |
var inner = outer | |
var i = 1 | |
while i < count { | |
inner = inner + x | |
i += 1 | |
switch Int(inner.truncatingRemainder(dividingBy: 7)) { | |
case 0: break outerLoop | |
case 1: break | |
default: continue | |
} | |
} | |
outer = inner | |
} | |
return outer | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment