Alejandro Martinez

24 May, 2016๐Ÿ”— Linked pageSwiftAlgorithms and Data StructuresC๐Ÿ• 1min read

Matt Gallagher on C-level performance in Swift

Getting C-level performance in Swift for numerical algorithms is quirky but not particularly difficult. If you limit yourself to value types (no classes or existentials), use unsafe pointers and tuples instead of arrays, use overflow discarding operators &+/&-/&* instead of normal +/-/*, use while or repeat/while for your loops, then Swift and clang C will generally compile to identical instructions.

Itโ€™s not as though C is maximally performant without a little contortion. Using int types for indexes on 64-bit systems should be avoided and so should common idioms like inline use of the ++ postincrement operator.

๐Ÿ‘‰๐Ÿป If you have any feedback you can reach me at alexito4

Alejandro Martinez
alexito4@gmail.com

Buka pintu