问题描述
我需要在数据库中存储很多二维数组,并且不确定要使用什么:serialize
或implode
.因此,我进行了一些测试,以找出哪个工作更快,并得出结论是serialize
:
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
所以问题是:为什么 implode + explode 比 serialize + unserialize 慢得多?
So the question: Why is implode+explode so much slower then serialize+unserialize?
PS:我已经发现了这个问题,但这并不是我要问的./p>
PS: I found this question already, but it is not exactly what I am asking.
推荐答案
我的想法是explode
/implode
对字符串进行操作,这就是为什么,而serialize
/unserialize
则在此位置输出/输入字符串结束/开始. implode
中的字符串越多,explode
中的字符串越长,它越慢,您是否尝试过?
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?
使用哪个我不知道,这取决于您以后是否要处理输出字符串,我认为serialize
d字符串更难解析.但是要将其存储在数据库或文件中,我将使用serialize
.
Which to use I don't know, it depends if you later wish to handle output string, I think serialize
d string is more difficult to parse. But to store it in database or file I'd use serialize
.
这篇关于序列化或放大的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!