A few months ago I wrote a post about JSON parsing libraries for Cocoa. I compared 4 libraries – BSJSONAdditions, JSON Framework, TouchJSON, and YAJL, I ran a benchmark on all of them, and the conclusion was that YAJL was the fastest and BSJSONAdditions was way slower than the rest.
Last week John Engelhart commented on that post, mentioning his own JSON library JSONKit, claiming that it’s really fast. Of course I had to check if that was true :)
I couldn’t just run the same test now on latest JSONKit and compare the result against the old results, that wouldn’t be very fair – so I checked the repositories of the other projects, downloaded latest versions and rerun all the tests.
Here are the results (I took a median value from 5 runs for every library):
- For BSJSONAdditions, TouchJSON and YAJL the results are very similar to what I got last time.
- BSJSONAdditions, which I used before and to which I even contributed some patches, is still slow as hell. The project was last updated in 2009, which means it’s basically dead. Don’t use it.
- TouchJSON and YAJL are still maintained (TouchJSON has moved from Google Code to GitHub); however, that didn’t make them any faster than before.
- JSON Framework has also moved to GitHub, and it seems the author has made a lot of progress on it: it’s now more or less 3× faster than before, which makes it slightly faster than YAJL, the previous winner.
- But the biggest surprise was JSONKit – it seems John was right, it really is super fast. It’s about 50% faster than YAJL and JSON Framework, and 20× faster than BSJSONAdditions. It’s also the easiest to install – it’s just two files, no frameworks, no subdirectories, no need to change anything in Xcode project settings.
So if you’re looking for a fast JSON library for your iPhone app, choose JSONKit.
Again, the test project is here (430 KB).
Update: John Engelhart told me that my JSON is a kind of worst case scenario, in that it contains mostly randomized data. In real data there should be much more repeating keys and values, which can be cached by JSONKit, and in such cases it should be even faster than here. Go figure…