php - 通过引用函数传递字符串会加快速度吗? (php)

标签 php optimization function pass-by-reference premature-optimization

<分区>

Possible Duplicate:
In PHP (>= 5.0), is passing by reference faster?

我想知道通过声明参数按引用传递,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;
}

比这更快:


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;
}

?

最佳答案

别想了,剖析

运行脚本,使用函数的每个版本重复 100,000 次,例如,在 Unix time 命令下。不要对什么是更快进行哲学思考;找出来。

关于php - 通过引用函数传递字符串会加快速度吗? (php),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1172622/

相关文章:

c++ - 康威的 C++ 生命游戏问题

javascript - 函数排序正常工作?

MySQL 索引大于存储的数据

python - scipy.optimize 的最小化函数没有给出正确答案

c++ - Atom 和 i3/5 之间常见的 gcc C/C++ 标志?

PHP - 严格的标准 : Only variables should be passed by reference

function - React 函数未定义

javascript - 多张幻灯片的 ORDER BY

php - yii2 radio 内联 Html 帮助程序

php - 拉拉维尔 5.4 : search by tag