加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ios – ObjC Plist文件读取比JSON更快?

发布时间:2020-12-14 19:32:18 所属栏目:百科 来源:网络整理
导读:我已经完成了这个测试项目 https://github.com/danielpetroianu/FileDeserializeBenchmarking,看看我能从应用程序包中读取文件的最快方式是什么,并反序列化它. 我很惊讶地看到Plist文件的读取速度比JSON快.由于JSON文件的大小较小,我预计它会更快. Xcode是否
我已经完成了这个测试项目 https://github.com/danielpetroianu/FileDeserializeBenchmarking,看看我能从应用程序包中读取文件的最快方式是什么,并反序列化它.

我很惊讶地看到Plist文件的读取速度比JSON快.由于JSON文件的大小较小,我预计它会更快.

Xcode是否在构建时对Plist文件进行了一些优化?
我做错了导致JSON反序列化花费更多时间吗?

解决方法

Since JSON files are smaller as size,I expected it to be faster.

你没理由相信这一点.有许多因素比文件大小重要得多.

Are there some optimizations that Xcode does on Plist files on build-time

是.如果它们在资源包中,它会将它们编译为Plist二进制格式,在某些情况下(实际上可能是所有情况),它比文本格式更快地读取和解析.这是在CopyPlistFile构建阶段完成的.

建成后,这是他们的样子:

-rwxr-xr-x  1 rnapier  wheel     39556 Oct  7 13:06 FileDeserializeBenchmarking
-rw-r--r--  1 rnapier  wheel       967 Oct  7 13:06 Info.plist
-rw-r--r--  1 rnapier  wheel         8 Oct  7 13:06 PkgInfo
-rw-r--r--  1 rnapier  wheel       111 Oct  7 13:06 data_dictionary_root_1.json
-rw-r--r--  1 rnapier  wheel       110 Oct  7 13:06 data_dictionary_root_1.plist
-rw-r--r--  1 rnapier  wheel       982 Oct  7 13:06 data_dictionary_root_10.json
-rw-r--r--  1 rnapier  wheel       441 Oct  7 13:06 data_dictionary_root_10.plist
-rw-r--r--  1 rnapier  wheel      9661 Oct  7 13:06 data_dictionary_root_100.json
-rw-r--r--  1 rnapier  wheel      4219 Oct  7 13:06 data_dictionary_root_100.plist
-rw-r--r--  1 rnapier  wheel     96488 Oct  7 13:06 data_dictionary_root_1000.json
-rw-r--r--  1 rnapier  wheel     37730 Oct  7 13:06 data_dictionary_root_1000.plist
-rw-r--r--  1 rnapier  wheel    965597 Oct  7 13:06 data_dictionary_root_10000.json
-rw-r--r--  1 rnapier  wheel    233071 Oct  7 13:06 data_dictionary_root_10000.plist
-rw-r--r--  1 rnapier  wheel  11655908 Oct  7 13:06 data_dictionary_root_100000.json
-rw-r--r--  1 rnapier  wheel   3343077 Oct  7 13:06 data_dictionary_root_100000.plist

$file *.plist
Info.plist:                        Apple binary property list
data_dictionary_root_1.plist:      Apple binary property list
data_dictionary_root_10.plist:     Apple binary property list
data_dictionary_root_100.plist:    Apple binary property list
data_dictionary_root_1000.plist:   Apple binary property list
data_dictionary_root_10000.plist:  Apple binary property list
data_dictionary_root_100000.plist: Apple binary property list

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读