Skip to content

Instantly share code, notes, and snippets.

@krzyzanowskim
Created March 16, 2015 20:36
Show Gist options
  • Select an option

  • Save krzyzanowskim/17c8e9ae467ff4e71ad9 to your computer and use it in GitHub Desktop.

Select an option

Save krzyzanowskim/17c8e9ae467ff4e71ad9 to your computer and use it in GitHub Desktop.
+ vs extend() performance
import Foundation
func perf(text: String, closure: () -> ()) {
let measurementStart = NSDate();
closure()
let measurementStop = NSDate();
let executionTime = measurementStop.timeIntervalSinceDate(measurementStart)
println("\(text) \(executionTime)");
}
let message = [UInt8](count: 1024 * 1024, repeatedValue: 7)
var out = [UInt8]()
out.reserveCapacity(message.count)
perf(" +") { () -> () in
out += [1]
}
perf("extend") { () -> () in
out.extend([1])
}
@krzyzanowskim
Copy link
Copy Markdown
Author

rdar://20178254

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment