Created
January 30, 2018 08:49
-
-
Save rizumita/11e76bad3a563b53ef10408debb39a37 to your computer and use it in GitHub Desktop.
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
func runSpeedTests() { | |
let s: String? = "test" | |
let repeatCount = 100000000 | |
test("Optional Binding") { | |
for _ in 0...repeatCount { | |
if let _ = s {} | |
} | |
} | |
test("eq not nil") { | |
for _ in 0...repeatCount { | |
if s != nil {} | |
} | |
} | |
test("switch") { | |
for _ in 0...repeatCount { | |
switch s { | |
case .some(_): () | |
case .none: () | |
} | |
} | |
} | |
} | |
func test(_ name: String, _ t: () -> ()) { | |
let methodStart = Date() | |
t() | |
let methodFinish = Date() | |
let executionTime = methodFinish.timeIntervalSince(methodStart) | |
print("Execution time - \(name): \(executionTime)") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment