Serialize or Implode

淺唱寂寞╮ 提交于 2019-12-18 13:17:20

问题


I need to store lots of two-dimensional arrays inside database and was not sure what to use: serialize or implode. So I did a few tests, to find out which one is working faster and came to the conclusion it was serialize:

Execution times: 1'000'000
Serialize: 1.4974119663239 seconds
Implode: 2.5333571434021 seconds
Explode: 4.0185871124268 seconds
Unserialize: 1.6835169792175 seconds 

So the question: Why is implode+explode so much slower then serialize+unserialize?

PS: I found this question already, but it is not exactly what I am asking.


回答1:


My idea is that explode/implode operate on strings that's why, while serialize/unserialize output/input a string at the very ending/beginning. Probably the more strings you implode and the longer string you explode, the slower it is, have you tried?

Which to use I don't know, it depends if you later wish to handle output string, I think serialized string is more difficult to parse. But to store it in database or file I'd use serialize.



来源:https://stackoverflow.com/questions/15218827/serialize-or-implode

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