var_export和serialize差别比我想象还大


看到一个blog谈到var_export这个函数,于是测试了下和serialize之间的效率对比,结果比我想象还大
$funcs=get_defined_functions();

$t1=microtime(true);
for($i=0;$i<1000;++$i){
	file_put_contents('test1.txt',var_export($funcs,true));
	eval(file_get_contents('test1.txt').';');
}
$t2=microtime(true);
for($i=0;$i<1000;++$i){
	file_put_contents('test2.txt',serialize($funcs));
	unserialize(file_get_contents('test2.txt'));
}
$t3=microtime(true);
echo "var_export cost ".($t2-$t1)."\n";
echo "serialize  cost ".($t3-$t2)."\n";
//var_export cost 9.58075594902
//serialize  cost 3.66198205948

你可能感兴趣的:(PHP,Blog)