Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Swift High Performance

You're reading from   Swift High Performance Leverage Swift and enhance your code to take your applications to the next level

Arrow left icon
Product type Paperback
Published in Nov 2015
Publisher Packt
ISBN-13 9781785282201
Length 212 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Kostiantyn Koval Kostiantyn Koval
Author Profile Icon Kostiantyn Koval
Kostiantyn Koval
Arrow right icon
View More author details
Toc

Table of Contents (10) Chapters Close

Preface 1. Exploring Swift's Power and Performance FREE CHAPTER 2. Making a Good Application Architecture in Swift 3. Testing and Identifying Slow Code with the Swift Toolkit 4. Improving Code Performance 5. Choosing the Correct Data Structure 6. Architecting Applications for High Performance 7. The Importance of Being Lazy 8. Discovering All the Underlying Swift Power 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!

You have been reading a chapter from
Swift High Performance
Published in: Nov 2015
Publisher: Packt
ISBN-13: 9781785282201
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime