5个开源库的JSON解析速度测试

iOS5新增了JSON解析的API,我们将其和其他五个开源的JSON解析库进行了解析速度的测试,下面是测试的结果。

我们选择的测试对象包含下面的这几个框架,其中NSJSONSerialization是iOS5系统新增的JSON解析的API,需要iOS5的环境,如果您在更低的版本进行测试,应该屏蔽相应的代码调用。

- [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)

我们选择了四个包含json格式的数据的文件进行测试。每一个文件进行100的解析动作,对解析的时间进行比较。



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

[img]http://www.cocoachina.com/cms/uploads/allimg/111129/3292_111129151636_1.gif[/img]

测试时间间隔的的代码的宏定义如下,其中计算的次数和解析的代码由外部调用传入:

#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)




这是外面调用的代码,设置读取的json文件和计算的次数,每一个函数在进行对应框架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];




我们的测试的环境是Xcode 4.2和iOS5,计算次数是100次,这是计算的结果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

将上面的数据整理成下面的图表:
[img]http://www.cocoachina.com/cms/uploads/allimg/111129/3292_111129151649_1.gif[/img]

测试的结果显示,系统的API的解析速度最快,我们在工程项目中选择使用,也是应用较为广泛的SBJSON的解析速度为倒数第二差,令我大跌眼镜。

与系统API较为接近的应该是JSONKit。

这里没有对API的开放接口和使用方式进行比较,若单纯基于以上解析速度的测试:

1:iOS5应该选择系统的API进行

2:不能使用系统API的应该选择JSONKit
MPC模型预测控制实战:从理论到代码实现(Python示例) 本文详细介绍了MPC模型预测控制的实战应用,从理论到Python代码实现。通过构建系统模型、预测方程、优化问题及约束处理,展示了如何实现一个完整的MPC控制器。文章还提供了水箱液位控制的应用案例,帮助读者掌握MPC在工业控制中的实际应用。 阅读详情

相关推荐

Win11+VSCode+TeXLive:学术党必备的LaTeX环境配置避坑指南(2024最新版)

本文详细介绍了如何在Windows 11系统下,通过VSCode编辑器与TeXLive发行版配置高效的LaTeX学术写作环境。针对国内用户常见的镜像下载慢、插件配置复杂等问题,提供了优化方案和避坑指南,帮助科研人员和学生快速搭建流畅的学术写作工作流。

plum99的博客 621

JSON用法+测试用例

JSON用法+测试用例

天道酬勤 7420

CSV文件输入到simulink中

将示波器波形和数据CSV文件保存下来进行数据分析。将波形绘制到simulink中

yay0923的博客 5327

iOS5系统API和5个开源库的JSON解析速度测试

iOS5新增了JSON解析的API,我们将其和其他五个开源的JSON解析库进行了解析速度的测试,下面是测试的结果和工程代码附件。 我们选择的测试对象包含下面的这几个框架,其中NSJSONSerialization是iOS5系统新增的JSON解析的API,需要iOS5的环境,如果您在更低的版本进行测试,应该屏蔽相应的代码调用。 - [SBJSON (json-f...

weixin_34362875的博客 165

基于Autoware制作高精地图(一)

基于Autoware制作高精地图(一) ​开始进入正题,也是最近在忙的一件事,制作高精地图。 高精地图的制作大概分为以下四个流程(不一定完全正确): 1.构建点云地图; 2.点云地图标注; 3.制作OpenDrive地图; 4.地图存储索引。 这篇文章主要讲解如何构建点云地图。 首先我们要有一段自己录制的激光雷达点云数据,这里推荐大家采用Velodyne16线激光雷达,因为这里我们构建的点云底图是三维的,而采用Velodyne而不是速腾聚创(rslidar)等其他品牌的原因是Autoware里面有一个选项是

weixin_44570248的博客 7800

用AG9311芯片DIY一个多功能Type-C扩展坞:从原理图到PCB布局的保姆级指南

本文详细介绍了如何利用AG9311芯片DIY多功能Type-C扩展坞,涵盖从原理图设计到PCB布局的全过程。AG9311芯片作为高性价比的Type-C控制器,支持HDMI 2.0、USB 3.0、PD快充和千兆网口,适合硬件爱好者打造个性化扩展坞。文章还提供了调试技巧和进阶优化建议,帮助读者轻松完成项目。

weixin_42520909的博客 405

iOS 加载(读取)本地的json文件

func countryOperator(){ let path = Bundle.main.path(forResource:"country_list", ofType:"json") let url = URL(fileURLWithPath: path!) let addressData = NSData.init(contentsOf: url) let addressDic = try! JSONSerialization....

baidu_40537062的博客 1796

富芮坤fr8008gp 240X280 lvgl项目启动

fr8008gp_240X280_lvgl项目启动

cheng___yi的博客 1758

IOS中Json解析的四种方法

作为一种轻量级的数据交换格式,json正在逐步取代xml,成为网络数据的通用格式。 有的json代码格式比较混乱,可以使用此“http://www.bejson.com/”网站来进行JSON格式化校验(点击打开链接)。此网站不仅可以检测Json代码中的错误,而且可以以视图形式显示json中的数据内容,很是方便。 从IOS5开始,APPLE提供了对json的原生支持(NSJSONSerial

集结号 31万+

C# 与华中数控设备通信:数控机床自动化控制与实时监测系统

华中数控系统与C#通信开发指南 核心要点 通信基础 支持串口(RS232/RS485)和以太网两种连接方式 协议选择:通用Modbus协议或华中自定义HNC协议 关键数据映射表明确各参数对应的寄存器地址和功能码 系统架构 四层架构:设备层→通信层→业务层→应用层 包含实时数据采集、指令下发、状态监控、异常处理全流程 支持Modbus和HNC协议动态切换 代码实现 串口通信使用NModbus库简化开发 提供连接管理、数据读取、指令下发完整示例 包含异常处理和超时重连机制 应用价值 实现数控机床远程监控和自动化

这里只有干货:从 Modbus 通信到 MES 对接,从 YOLO 训练到工控机部署,带你搞定工业软件开发全流程。 2019

ZYNQ PS裸机开发RS485

RS485 是一种通用的通信标准,广泛用于数据采集和控制应用中。它的主要优点之一是它允许将多个 RS485 设备放在同一条总线上,这使得多个节点可以相互连接。RS-485是美国电子工业协会(EIA)在1983年批准了一个新的平衡传输标准(balanced transmission standard),EIA一开始将RS(Recommended Standard)做为标准的前缀,不过后来为了便于识别标准的来源,已将RS改为EIA/TIA。

baidu_34971492的博客 831

【C/C++】C++Json解析和生成的开源库:RapidJson和JsonCpp

RapidJson和JsonCpp都是C++中流行的JSON解析器和生成器,并且都是开源库,具有许多相似的功能,但也有不同之处,具体使用都有所介绍,并写有例子来加深理解!

weixin_43729127的博客 4252

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

上一篇: IOS 5编程 内存管理 ARC技术概述
下一篇: 10个迷惑新手的Cocoa,Objective-c开发难点和问题
iteye_3205
博客等级 码龄8年 0粉丝 44原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值