Skip to content

Instantly share code, notes, and snippets.

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

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

Select an option

Save krzyzanowskim/aabe4123e5f348eb306e to your computer and use it in GitHub Desktop.
slow copying
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)
@krzyzanowskim
Copy link
Copy Markdown
Author

rdar://20173825

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