I need to cache some data to disk between PHP requests so I decided to compare the various methods available.
Using 100000 element array as source data
Serialize save: 2.958 ms (1.5M)
Serialize read: 5.447 ms
JSON save: 1.880 ms (574.96K)
JSON read: 6.876 ms
PHP save: 8.684 ms (1.7M)
PHP read: 26.863 ms
Memcache set: 5.651 ms
Memcache get: 2.465 ms
IGBinary save: 1.377 ms (720.08K)
IGBinary read: 2.245 ms
MsgPack save: 1.389 ms (359.92K)
MsgPack read: 2.930 ms
I was surprised to see IGBinary and MsgPack so much faster than native JSON. JSON is easy and super portable, but not the fastest.