Book Image

Swift High Performance

By : Kostiantyn Koval
Book Image

Swift High Performance

By: Kostiantyn Koval

Overview of this book

Swift is one of the most popular and powerful programming languages for building iOS and Mac OS applications, and continues to evolve with new features and capabilities. Swift is considered a replacement to Objective-C and has performance advantages over Objective-C and Python. Swift adopts safe programming patterns and adds modern features to make programming easier, more flexible, and more fun. Develop Swift and discover best practices that allow you to build solid applications and optimize their performance. First, a few of performance characteristics of Swift will be explained. You will implement new tools available in Swift, including Playgrounds and REPL. These will improve your code efficiency, enable you to analyse Swift code, and enhance performance. Next, the importance of building solid applications using multithreading concurrency and multi-core device architecture is covered, before moving on to best practices and techniques that you should utilize when building high performance applications, such as concurrency and lazy-loading. Finally, you will explore the underlying structure of Swift further, and learn how to disassemble and compile Swift code.
Table of Contents (15 chapters)
Swift High Performance
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Swift speed


I can guess you opened this book because you are interested in speed and are probably wondering, "How fast can Swift be?" Before you even start learning Swift and discovering all the good things about it, let's answer it right here and right now.

Let's take an array of 100,000 random numbers; sort it in Swift, Objective-C, and C using the standard sort function from stdlib (sort in Swift, qsort in C, and compare in Objective-C); and measure how much time each would take.

Sorting an array with 100,000 integer elements gives us this:

Technology

Time taken

Swift

0.00600 sec

C

0.01396 sec

Objective-C

0.08705 sec

And the winner is, Swift! Swift is 14.5 times faster than Objective-C and 2.3 times faster than C.

In other examples and experiments, C is usually faster than Swift and Swift is way faster than Objective-C. These measurements were done with Xcode 7.0 beta 6 and Swift 2.0. It's important to highlight that the improvements in Swift 2.0 were mainly focused on making it cleaner, more powerful, safer, and more stable, and preparing it for open sourcing. Swift's performance hasn't reached its full potential yet, and the future is so exciting!