Skip to content

Instantly share code, notes, and snippets.

@53ningen
Created April 17, 2016 19:17
Show Gist options
  • Save 53ningen/3071618f99012875c32bff77a992e07a to your computer and use it in GitHub Desktop.
Save 53ningen/3071618f99012875c32bff77a992e07a to your computer and use it in GitHub Desktop.
### 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