我做过这个测试项目https://github.com/danielpetroianu/FileDeserializeBenchmarking https://github.com/danielpetroianu/FileDeserializeBenchmarking查看从应用程序包中读取文件并将其反序列化的最快方法是什么。
我很惊讶地发现 Plist 文件的读取速度比 JSON 更快。由于 JSON 文件较小,我预计它会更快。
Xcode 在构建时对 Plist 文件进行了一些优化吗?
我是否做错了什么导致 JSON 反序列化需要更多时间?
由于 JSON 文件较小,我预计它会更快。
你没有理由相信这一点。有许多因素比文件大小重要得多。
Xcode 在构建时对 Plist 文件进行了一些优化吗
是的。如果它们在资源包中,它会将它们编译为 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
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)