Created
August 5, 2019 20:13
-
-
Save AviTsadok/e79cdb6a20a3b46bc993061ea0c004a5 to your computer and use it in GitHub Desktop.
Performance Tests - Inline Code
This file contains 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
class PerformanceTuningTests: XCTestCase { | |
func testStackFunction() { | |
let methodAccess = MethodAccess() | |
self.measure { | |
for _ in 0...100000000 { | |
_ = methodAccess.stackFunction(x: 100) | |
} | |
} | |
} | |
func testInlineFunction() { // this test runs faster | |
let methodAccess = MethodAccess() | |
self.measure { | |
for _ in 0...100000000 { | |
_ = methodAccess.inlineFunction(x: 100) | |
} | |
} | |
} | |
} | |
class MethodAccess: NSObject { | |
func stackFunction(x : Int)->Int { | |
return checkX(y: x) | |
} | |
func inlineFunction(x : Int)->Int { | |
// do something | |
} | |
func checkX(y : Int)->Int { | |
// do something | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@AviTsadok It looks like the
@inline(__always)
annotation is missing. 🙄