Created
March 16, 2015 16:08
-
-
Save krzyzanowskim/aabe4123e5f348eb306e to your computer and use it in GitHub Desktop.
slow copying
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
| extension Array { | |
| /** split in chunks with given chunk size */ | |
| func chunks(chunksize:Int) -> [Array<T>] { | |
| var words:[[T]] = [[T]]() | |
| words.reserveCapacity(self.count / chunksize) | |
| for var idx = chunksize; idx <= self.count; idx = idx + chunksize { | |
| let word = Array(self[idx - chunksize..<idx]) // this is slow | |
| words.append(word) // slower than this | |
| } | |
| let reminder = Array(suffix(self, self.count % chunksize)) | |
| if (reminder.count > 0) { | |
| words.append(reminder) | |
| } | |
| return words | |
| } | |
| } | |
| let message = [UInt8](count: 1024 * 1024, repeatedValue: 7) | |
| //message.chunks(16) |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
rdar://20173825