Pet*_*uza 2 php optimization function pass-by-reference premature-optimization
我想知道是否通过引用声明参数传递,PHP解释器将更快,因为不必将字符串复制到函数的本地范围?该脚本将XML文件转换为CSV,其中包含数千条记录,因此很少有时间优化.
这会是:
function escapeCSV( & $string )
{
$string = str_replace( '"', '""', $string ); // escape every " with ""
if( strpos( $string, ',' ) !== false )
$string = '"'.$string.'"'; // if a field has a comma, enclose it with dobule quotes
return $string;
}
Run Code Online (Sandbox Code Playgroud)
要快于此:
function escapeCSV( $string )
{
$string = str_replace( '"', '""', $string ); // escape every " with ""
if( strpos( $string, ',' ) !== false )
$string = '"'.$string.'"'; // if a field has a comma, enclose it with dobule quotes
return $string;
}
Run Code Online (Sandbox Code Playgroud)
?
不要想,个人资料.
例如,在Unix time命令下运行使用该函数的每个版本100,000次重复的脚本.不要对什么是更快的进行哲学思考; 找出.