Skip to content

Instantly share code, notes, and snippets.

@ioquatix
Created June 2, 2022 11:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ioquatix/e58cb756c4072fde7ae7961a5be08d56 to your computer and use it in GitHub Desktop.
Save ioquatix/e58cb756c4072fde7ae7961a5be08d56 to your computer and use it in GitHub Desktop.
UIImage Performance
extension DispatchTimeInterval {
func toDouble() -> Double? {
var result: Double? = 0
switch self {
case .seconds(let value):
result = Double(value)
case .milliseconds(let value):
result = Double(value)*0.001
case .microseconds(let value):
result = Double(value)*0.000001
case .nanoseconds(let value):
result = Double(value)*0.000000001
case .never:
result = nil
}
return result
}
}
import UIKit
let path = Bundle.main.path(forResource: "dog", ofType: "png")!
let startTime = DispatchTime.now()
// On my laptop, takes around 120ms.
let image = UIKit.UIImage.init(contentsOfFile: path)!
let endTime = DispatchTime.now()
image.size
let duration = startTime.distance(to: endTime).toDouble()!
print("Time to evaluate: \(duration*1000.0)ms")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment