我把一个 php 数组分别保存为 serialize 和 json,然后
$start = microtime(true);
for($i = 0; $i < 1000; $i++){
$ser = file_get_contents('gdip.ser');
$arr = unserialize($ser);
}
$l = microtime(true) - $start;
echo $l."\n";
//
$start = microtime(true);
for($i = 0; $i < 1000; $i++){
$json = file_get_contents('gdip.json');
$arr = json_decode($json, true);
}
$l = microtime(true) - $start;
echo $l."\n";
然后运行得到的结果
0.939453125
2.0195319652557
这能不能说明保存成 serialize 格式读取效率更快?