funcmeasure(title: String!, call: () -> Void) { let startTime =CACurrentMediaTime() call() let endTime =CACurrentMediaTime() iflet title = title { print("\(title): ") } print("Time - \(endTime - startTime)") }
1 2 3 4 5 6 7 8 9 10 11 12
funcdoSomeWork() { measure("Array") { var ar = [String]() for i in0...10000 { ar.append("New elem \(i)") } } measure("Image") { let url =NSURL(string: "http://lorempixel.com/1920/1920/") let image =UIImage(data:NSData(contentsOfURL:url!)!) } }