IOS5 system API and JSON parsing speed test for five open-source libraries

Source: Internet
Author: User

IOS5 added the JSON parsing API. We tested the parsing speed with the other five open-source JSON parsing libraries. Below are the test results and Engineering Code attachments.

The selected test object includes the following frameworks. NSJSONSerialization is a JSON-parsed API added by the iOS5 system and requires an iOS5 environment. If you perform a test in a lower version, code calls should be blocked. -[SBJSON (json-framework)] (http://code.google.com/p/json-framework/)-[TouchJSON (from touchcode)] (http://code.google.com/p/touchcode/)-[YAJL (objective-C bindings)] (http://github.com/gabriel/yajl-objc) -[JSONKit] (https://github.com/johnezang/JSONKit)-[NextiveJson] (https://github.com/nextive/NextiveJson)-[NSJSONSerialization] (http://developer.apple.com/library/ios/#documentation/Foundation/Refe Rence/NSJSONSerialization_Class/Reference/Reference.html # // apple_ref/doc/uid/tp400000046) We selected four files containing json data for testing. Each file performs 100 parsing actions to compare the parsing time. The project contains the following files and frameworks:

650) this. width = 650; "border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131228/1G10I428-0.png "/>

The macro Definition of the code for the test interval is as follows. The calculation frequency and resolution code are passed in by external calls:

# Define RunWithCount (count, description, expr) \ do {\ CFAbsoluteTime start = CFAbsoluteTimeGetCurrent (); \ for (NSInteger I = 0; I <count; I ++) {\ NSAID utoreleasepool * pool = [[NSAID utoreleasepool alloc] init]; \ expr; \ [pool release]; \ }\\ CFTimeInterval took = CFAbsoluteTimeGetCurrent ()-start; \ NSLog (@ "% @ % 0.3f", description, took); \\} while (0)

This is the code called outside. It sets the number of reads to the json file and the number of computations. Each function is parsing the code of the corresponding framework API:

JSONTest * test = [[JSONTest alloc] init]; NSInteger count = 100; [test runWithResourceName: @ "twitter_public.json" count: count]; [test runWithResourceName: @ "lastfm. json "count: count]; [test runWithResourceName: @" delicious_popular.json "count: count]; [test runWithResourceName: @" yelp. json "count: count];

In our testing environment, Xcode 4.2 and iOS5 are used, and the number of computations is 100. This is the calculation result Log:

14:48:59. 441 JSONPerfTest [9716: 207] SBJSON-twitter_public.json 0.335 14:48:59. 625 JSONPerfTest [9716: 207] YAJL-twitter_public.json 0.183 14:49:00. JSONPerfTest [9716: 207] TouchJSON-twitter_public.json 0.469 14:49:00. 226 JSONPerfTest [9716: 207] JSONKit-twitter_public.json 0.130 14:49:00. 390 JSONPerfTest [9716: 207] NextiveJson-twitter_public.json 0.164 14:49:00. 504 JSONPerfTest [9716: 207] NSJSONSerialization-twitter_public.json 0.113 14:49:01. 196 JSONPerfTest [9716: 207] SBJSON-lastfm.json 0.691 14:49:01. 516 JSONPerfTest [9716: 207] YAJL-lastfm.json 0.320 14:49:02. 367 JSONPerfTest [9716: 207] TouchJSON-lastfm.json 0.850 14:49:02. 580 JSONPerfTest [9716: 207] JSONKit-lastfm.json 0.212 14:49:02. 861 JSONPerfTest [9716: 207] NextiveJson-lastfm.json 0.280 14:49:03. 039 JSONPerfTest [9716: 207] NSJSONSerialization-lastfm.json 0.177 14:49:03. 546 JSONPerfTest [9716: 207] SBJSON-delicious_popular.json 0.506 14:49:03. 787 JSONPerfTest [9716: 207] YAJL-delicious_popular.json 0.240 14:49:04. 460 JSONPerfTest [9716: 207] TouchJSON-delicious_popular.json 0.672 14:49:04. 668 JSONPerfTest [9716: 207] JSONKit-delicious_popular.json 0.207 14:49:04. 904 JSONPerfTest [9716: 207] NextiveJson-delicious_popular.json 0.234 14:49:05. JSONPerfTest [9716: 207] NSJSONSerialization-delicious_popular.json 0.168 14:49:05. 434 JSONPerfTest [9716: 207] SBJSON-yelp.json 0.361 14:49:05. 633 JSONPerfTest [9716: 207] YAJL-yelp.json 0.198 14:49:06. 154 JSONPerfTest [9716: 207] TouchJSON-yelp.json 0.519 14:49:06. 310 JSONPerfTest [9716: 207] JSONKit-yelp.json 0.155 14:49:06. 497 JSONPerfTest [9716: 207] NextiveJson-yelp.json 0.186 14:49:06. 637 JSONPerfTest [9716: 207] NSJSONSerialization-yelp.json 0.140

Organize the above data into the following chart:

650) this. width = 650; "border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131228/1G10I495-1.png "/>

The test results show that the system's API parsing speed is the fastest. We chose to use it in engineering projects. The SBJSON parsing speed, which is widely used, is the second to the last, which surprised me. JSONKit is closer to the system API. There is no comparison between open APIs and usage methods. If the test is based solely on the above resolution speed: 1: iOS5, select the system API for 2: if you cannot use the system API, select the JSONKit attachment as the program source code and the Word document.

This article is from the "arsurchen" blog, please be sure to keep this source http://arthurchen.blog.51cto.com/2483760/723910

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.