This post is a quick update to Vombat’s blog post about using SQL instead of
NSDateFormatter when it comes to parsing dates in your project. If you don’t read it yet, I will highly recommend to do it now. This time we will use Swift to make same measurements.
You can use sql database function
strftime to get UNIX time from e.g.: ISO8061 date string.
Here is the magic function:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
We will use it to replace standard parsing method like this:
1 2 3 4 5
I did some measurements using iPhone 5S with iOS8.2 in release configuration running exactly same amount of data (One Milion strings with ISO8601 date)
And here are the results:
So using SQL to format string into date is pretty fast but acutally slower than objC version (But still at least 10time faster than regular method) So what about Swift?. Nothing really changed, overall results show faster computation but I’m using better CPU so
NSDateFormatter is still very very slow… If you like it, sample source code is available on Github