Skip to content

Instantly share code, notes, and snippets.

@AviTsadok
Created August 5, 2019 20:13
Show Gist options
  • Save AviTsadok/e79cdb6a20a3b46bc993061ea0c004a5 to your computer and use it in GitHub Desktop.
Save AviTsadok/e79cdb6a20a3b46bc993061ea0c004a5 to your computer and use it in GitHub Desktop.
Performance Tests - Inline Code
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
}
}
@chosa91
Copy link

chosa91 commented Feb 2, 2023

@AviTsadok It looks like the @inline(__always) annotation is missing. 🙄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment