Swift with Speed of the Light

Kostiantyn Koval
Swift Programming
Published in
1 min readApr 5, 2015

--

I’m very interested in discovering Swift performance and I wrote few blogs about it. I get really interested in comparing C vs Swift after reading Jesse Squires’s article.

Swift vs C

I wanted to compare the most trivial task in Swift and C — for loop

C

Swift

Results: (in release mode of course)

C: 0.000002 sec
Swift: 0.0928 sec

Wow that was fast in C! Hold on a second. It seems like C does some powerful optimisation and doesn’t do any actual calculation in the loop, but calculates the result at compile time. (I changed the number of the iterations and the result stays the same.)

Let’s make the task a bit harder and generate random numbers.
I changed the loop body to :

sum += arc4random_uniform(UINT32_MAX)

Results:
C: 1.979127 sec
Swift: 1.978747 sec

Swift Speed = C Speed

☺☺☺☺☺☺☺☺☺☺☺☺☺☺☺☺☺☺☺☺☺☺☺☺☺☺☺☺

Want to Learn More?

Check out “Swift Hight Performance” book

--

--

Kostiantyn Koval
Swift Programming

Life Coach — Helping people to achieve their dreams, life fully, love passionate and live life of no regrets