自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

iOS5系統(tǒng)API和5個(gè)開(kāi)源庫(kù)的JSON解析速度測(cè)試

移動(dòng)開(kāi)發(fā) iOS
我們選擇了四個(gè)包含json格式的數(shù)據(jù)的文件進(jìn)行測(cè)試。每一個(gè)文件進(jìn)行100的解析動(dòng)作,對(duì)解析的時(shí)間進(jìn)行比較。


iOS5新增了JSON解析的API,我們將其和其他五個(gè)開(kāi)源的JSON解析庫(kù)進(jìn)行了解析速度的測(cè)試,下面是測(cè)試的結(jié)果和工程代碼附件。

 

我們選擇的測(cè)試對(duì)象包含下面的這幾個(gè)框架,其中NSJSONSerialization是iOS5系統(tǒng)新增的JSON解析的API,需要iOS5的環(huán)境,如果您在更低的版本進(jìn)行測(cè)試,應(yīng)該屏蔽相應(yīng)的代碼調(diào)用。

 

- [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/Reference/NSJSONSerialization_Class/Reference/Reference.html#//apple_ref/doc/uid/TP40010946)

 

我們選擇了四個(gè)包含json格式的數(shù)據(jù)的文件進(jìn)行測(cè)試。每一個(gè)文件進(jìn)行100的解析動(dòng)作,對(duì)解析的時(shí)間進(jìn)行比較。

 

工程包含以下的文件和框架:

 [[106698]]

測(cè)試時(shí)間間隔的的代碼的宏定義如下,其中計(jì)算的次數(shù)和解析的代碼由外部調(diào)用傳入:

#define RunWithCount(count, description, expr) \

do { \

CFAbsoluteTime start = CFAbsoluteTimeGetCurrent(); \

for(NSInteger i = 0; i < count; i++) { \

         NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; \

         expr; \

         [pool release]; \

} \

\

CFTimeInterval took = CFAbsoluteTimeGetCurrent() - start; \

NSLog(@"%@ %0.3f", description, took); \

\

} while (0)

 

這是外面調(diào)用的代碼,設(shè)置讀取的json文件和計(jì)算的次數(shù),每一個(gè)函數(shù)在進(jìn)行對(duì)應(yīng)框架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];

 

我們的測(cè)試的環(huán)境是Xcode 4.2和iOS5,計(jì)算次數(shù)是100次,這是計(jì)算的結(jié)果Log:

2011-11-24 14:48:59.441 JSONPerfTest[9716:207] SBJSON-twitter_public.json 0.335

2011-11-24 14:48:59.625 JSONPerfTest[9716:207] YAJL-twitter_public.json 0.183

2011-11-24 14:49:00.095 JSONPerfTest[9716:207] TouchJSON-twitter_public.json 0.469

2011-11-24 14:49:00.226 JSONPerfTest[9716:207] JSONKit-twitter_public.json 0.130

2011-11-24 14:49:00.390 JSONPerfTest[9716:207] NextiveJson-twitter_public.json 0.164

2011-11-24 14:49:00.504 JSONPerfTest[9716:207] NSJSONSerialization-twitter_public.json 0.113

2011-11-24 14:49:01.196 JSONPerfTest[9716:207] SBJSON-lastfm.json 0.691

2011-11-24 14:49:01.516 JSONPerfTest[9716:207] YAJL-lastfm.json 0.320

2011-11-24 14:49:02.367 JSONPerfTest[9716:207] TouchJSON-lastfm.json 0.850

2011-11-24 14:49:02.580 JSONPerfTest[9716:207] JSONKit-lastfm.json 0.212

2011-11-24 14:49:02.861 JSONPerfTest[9716:207] NextiveJson-lastfm.json 0.280

2011-11-24 14:49:03.039 JSONPerfTest[9716:207] NSJSONSerialization-lastfm.json 0.177

2011-11-24 14:49:03.546 JSONPerfTest[9716:207] SBJSON-delicious_popular.json 0.506

2011-11-24 14:49:03.787 JSONPerfTest[9716:207] YAJL-delicious_popular.json 0.240

2011-11-24 14:49:04.460 JSONPerfTest[9716:207] TouchJSON-delicious_popular.json 0.672

2011-11-24 14:49:04.668 JSONPerfTest[9716:207] JSONKit-delicious_popular.json 0.207

2011-11-24 14:49:04.904 JSONPerfTest[9716:207] NextiveJson-delicious_popular.json 0.234

2011-11-24 14:49:05.072 JSONPerfTest[9716:207] NSJSONSerialization-delicious_popular.json 0.168

2011-11-24 14:49:05.434 JSONPerfTest[9716:207] SBJSON-yelp.json 0.361

2011-11-24 14:49:05.633 JSONPerfTest[9716:207] YAJL-yelp.json 0.198

2011-11-24 14:49:06.154 JSONPerfTest[9716:207] TouchJSON-yelp.json 0.519

2011-11-24 14:49:06.310 JSONPerfTest[9716:207] JSONKit-yelp.json 0.155

2011-11-24 14:49:06.497 JSONPerfTest[9716:207] NextiveJson-yelp.json 0.186

2011-11-24 14:49:06.637 JSONPerfTest[9716:207] NSJSONSerialization-yelp.json 0.140

 

將上面的數(shù)據(jù)整理成下面的圖表:

 [[106699]]

測(cè)試的結(jié)果顯示,系統(tǒng)的API的解析速度最快,我們?cè)诠こ添?xiàng)目中選擇使用,也是應(yīng)用較為廣泛的SBJSON的解析速度為倒數(shù)第二差,令我大跌眼鏡。

與系統(tǒng)API較為接近的應(yīng)該是JSONKit。

 

這里沒(méi)有對(duì)API的開(kāi)放接口和使用方式進(jìn)行比較,若單純基于以上解析速度的測(cè)試:

1:iOS5應(yīng)該選擇系統(tǒng)的API進(jìn)行

2:不能使用系統(tǒng)API的應(yīng)該選擇JSONKit

 

程序附件:

http://arthurchen.blog.51cto.com/attachment/201111/2483760_1322144362.zip

本文word文檔:

http://arthurchen.blog.51cto.com/attachment/201111/2483760_1322144787.zip

責(zé)任編輯:冰凝兒 來(lái)源: 轉(zhuǎn)自:http://blog.csdn.net/arthurchenjs/article/de
相關(guān)推薦

2012-04-04 22:36:52

iOS5

2011-09-19 15:42:33

TwitteriOS5

2011-08-09 14:25:43

蘋(píng)果iCloudiOS5

2012-01-18 14:14:29

iOS教程iOS5

2012-01-18 13:51:39

2012-05-27 20:21:40

2011-05-31 22:53:14

喬布斯WWDCiCloud

2013-03-25 13:41:10

iOS5ARC內(nèi)存管理

2013-07-22 14:47:56

iOS開(kāi)發(fā)iOS5中ASIHtt

2011-06-07 07:06:33

iOS 5iOSWWDC

2019-11-26 09:11:50

數(shù)據(jù)庫(kù)JavaHadoop

2019-09-09 14:52:23

開(kāi)源速讀應(yīng)用

2011-10-05 01:51:20

iOS5蘋(píng)果

2018-11-02 08:30:43

開(kāi)源數(shù)據(jù)庫(kù)技巧

2011-08-09 14:47:28

蘋(píng)果iOS 5

2011-06-07 06:59:51

iOS 5iOS蘋(píng)果

2020-12-01 10:59:05

人工智能

2011-08-05 11:04:27

iOS 5蘋(píng)果

2020-08-23 09:12:52

JavaJava IDE框架

2013-03-27 10:51:44

iOSjson解析網(wǎng)絡(luò)交互數(shù)據(jù)格式解析
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)