ObjC Plist file read is faster then JSON?

别说谁变了你拦得住时间么 提交于 2020-01-02 04:35:08

问题


I've did this test project https://github.com/danielpetroianu/FileDeserializeBenchmarking to see what is the fastest way I can read a file from the app bundle and deserialize it.

I was surprised to see that Plist files are being read faster then 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 ? Have I done something wrong that causes JSON deserialization take more time ?


回答1:


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

There's no reason you should believe that. There are many factors that are much more important than file size.

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

Yes. If they're in the resource bundle, it will compile them to the Plist binary format, which is faster to read and parse than text formats in some cases (probably all cases really). This is done in the CopyPlistFile build stage.

After building, here's what they look like:

-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


来源:https://stackoverflow.com/questions/26193007/objc-plist-file-read-is-faster-then-json

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!