Created
March 16, 2015 20:36
-
-
Save krzyzanowskim/17c8e9ae467ff4e71ad9 to your computer and use it in GitHub Desktop.
+ vs extend() performance
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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]) | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
rdar://20178254