Created
April 17, 2016 19:17
-
-
Save 53ningen/3071618f99012875c32bff77a992e07a to your computer and use it in GitHub Desktop.
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
### nil check for boolean | |
``` | |
% cat ./NilCheckForBoolean.swift | |
import Foundation | |
func target() { | |
for _ in 1...100000 { | |
let e: Bool? = true | |
if e == nil { } | |
} | |
} | |
for i in 1...100 { | |
let start = NSDate() | |
target() | |
let end = NSDate() | |
let time = end.timeIntervalSince1970 - start.timeIntervalSince1970 | |
print("\(time)") | |
sleep(1) | |
} | |
``` | |
### nil check for enum | |
``` | |
% cat ./NilCheckForEnum.swift | |
import Foundation | |
enum E<T> { | |
case A(T) | |
case B(T) | |
} | |
func target() { | |
for _ in 1...100000 { | |
let e: E<Int>? = .A(1) | |
if e == nil { } | |
} | |
} | |
for i in 1...100 { | |
let start = NSDate() | |
target() | |
let end = NSDate() | |
let time = end.timeIntervalSince1970 - start.timeIntervalSince1970 | |
print("\(time)") | |
sleep(1) | |
} | |
``` | |
### result(enum) | |
### result(boolean) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment