Cocoa JSON parsing libraries, part 2

Kuba Suder 🇵🇱🇺🇦 December 12, 2010
Source
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): Simulator Framework time [s] BSJSONAdditions 0.184697 TouchJSON 0.037910 YAJL 0.016679 JSON Framework 0.015583 JSONKit 0.012852 Device Framework time [s] BSJSONAdditions 10.526504 TouchJSON 2.323277 YAJL 1.021358 JSON Framework 0.907641 JSONKit 0.587229 Conclusions: 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…

Discussion in the ATmosphere

Loading comments...