I need to store a multi-dimensional associative array of data in a flat file for caching purposes. I might occasionally come across the need to convert it to JSON for use in
I made a small benchmark as well. My results were the same. But I need the decode performance. Where I noticed, like a few people above said as well, unserialize
is faster than json_decode
. unserialize
takes roughly 60-70% of the json_decode
time. So the conclusion is fairly simple:
When you need performance in encoding, use json_encode
, when you need performance when decoding, use unserialize
. Because you can not merge the two functions you have to make a choise where you need more performance.
My benchmark in pseudo:
On avarage: unserialize won 96 times over 4 times the json_decode. With an avarage of roughly 1.5ms over 2.5ms.