环境 php7_64 win7 命令行运行
//生成数组
$stime = microtime(true);
$a = array();
for($i=1;$i<3000000;$i++){
$key = $i*2+$i ;
$a[$key]=array();
for($j=0;$j<4;$j++){
$a[$key][$j]=rand(1,100000000);
}
}
$etime = microtime(true);
echo iconv('UTF-8', 'GB2312//IGNORE',"生成数据耗时 :" . ($etime - $stime) . "\r\n" );
$stime = microtime(true);
$json = json_encode($a);
$etime = microtime(true);
echo iconv('UTF-8', 'GB2312//IGNORE',"json文本长度 :" . strlen($json) . "\r\n" );
echo iconv('UTF-8', 'GB2312//IGNORE',"数组转json耗时 :" . ($etime - $stime) . "\r\n" );
$stime = microtime(true);
$serialize = serialize($a);
$etime = microtime(true);
echo iconv('UTF-8', 'GB2312//IGNORE',"php自带 数组转文本 文本长度 :" . strlen($serialize) . "\r\n" );
echo iconv('UTF-8', 'GB2312//IGNORE',"php自带 数组转文本 耗时 :" . ($etime - $stime) . "\r\n" );
$stime = microtime(true);
$a = json_decode($json);
$etime = microtime(true);
echo iconv('UTF-8', 'GB2312//IGNORE',"json 文本转数组 耗时 :" . ($etime - $stime) . "\r\n" );
$stime = microtime(true);
$a = unserialize($serialize);
$etime = microtime(true);
echo iconv('UTF-8', 'GB2312//IGNORE',"php自带 文本转数组 耗时 :" . ($etime - $stime) . "\r\n" );
结果
D:\phpchina\phpchina\fengxiMac>D:\wapm\php-7\php -f ..\cesi.php 生成数据耗时 :4.7972741127014 json文本长度 :142294685 数组转json耗时 :2.7271559238434 php自带 数组转文本 文本长度 :226294668 php自带 数组转文本 耗时 :6.0113439559937 json 文本转数组 耗时 :15.242871999741 php自带 文本转数组 耗时 :7.3504211902618