我需要在数据库中存储许多二维数组,但不确定该使用什么: serialize 或 implode 。所以我做了一些测试,找出哪一个工作得更快,得出的结论是 序列化 :
serialize
implode
序列化
Execution times: 1'000'000 Serialize: 1.4974119663239 seconds Implode: 2.5333571434021 seconds Explode: 4.0185871124268 seconds Unserialize: 1.6835169792175 seconds
所以问题是:为什么 内爆+爆炸 那么慢多了 序列化+取消序列化 ?
附言:我找到了 this 这个问题已经提过了,但这并不是我要问的。
我的想法是 explode / implode 对字符串进行操作,这就是为什么,而 serialize / unserialize 在末尾/开头输出/输入一个字符串。也许你的弦越多 向心聚爆 你的绳子越长 爆炸 ,越慢,你试过了吗?
explode
unserialize
向心聚爆
爆炸
我不知道该用哪一个,这取决于你以后是否希望处理输出字符串,我想 序列化 d字符串更难解析。但要将其存储在数据库或文件中,我会使用 序列化 .