标题: Swift 提升性能的秘密 Part 1 - Measure [打印本页] 作者: 阿泽泽 时间: 2016-5-19 18:20 标题: Swift 提升性能的秘密 Part 1 - Measure 原文由Kostiantyn Koval发表于Medium,地址为Secret of Swift Performance :Part 1 — Measure
func doSomeWork() {
measure("Array") {
var ar = [String]()
for i in 0...10000 {
ar.append("New elem \(i)")
}
}
measure("Image") {
let url = NSURL(string: "http://lorempixel.com/1920/1920/")
let image = UIImage(data:NSData(contentsOfURL:url!)!)
}
}
测试结果是
Array: Time — 0.0845723639995413
Image: Time — 1.77442857499955作者: 1871037345 时间: 2016-5-19 18:26
感觉好高大上的样子,抽空得学习一下 Swift作者: lichuanlong 时间: 2016-5-20 00:17