Created
April 6, 2017 00:56
-
-
Save onevcat/b2e6a85d914ad394a9cfd89e8821bc22 to your computer and use it in GitHub Desktop.
Method literal performance
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
import QuartzCore | |
var a = 1 | |
func methodParams(file: String = #file, fun: String = #function, line: UInt = #line) -> Int { | |
a += 1 | |
return a | |
} | |
func method() -> Int { | |
a += 1 | |
return a | |
} | |
let startTimeParams = CACurrentMediaTime() | |
for _ in 1 ..< 1000000 { | |
_ = methodParams() | |
} | |
let endTimeParams = CACurrentMediaTime() | |
print("With params: \(endTimeParams - startTimeParams)") | |
let startTime = CACurrentMediaTime() | |
for _ in 1 ..< 1000000 { | |
_ = method() | |
} | |
let endTime = CACurrentMediaTime() | |
print("Without params: \(endTime - startTime)") |
Author
onevcat
commented
Apr 6, 2017
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment