Which is better on performance: double quoted strings with variables or single quoted strings with concatenations?

前端 未结 7 1969
暗喜
暗喜 2020-12-11 07:17

I know that using single quotes around a string in PHP is faster than using the double quotes because PHP doesn\'t need to check for variable presence in the single quoted s

相关标签:
7条回答
  • 2020-12-11 08:02

    I tested with timing (microtime) on my Vista/php5 box with two loops, one for ' and one for ".

    On 100 iterations: - single quotes: 0.000139 - double quotes: 0.000228

    On 1000 iterations: - single quotes: 0.002377 - double quotes: 0.002056

    On 2000 iterations: - single quotes: 0.003562 - double quotes: 0.010041

    EDIT: also timing echo 'Foo', $bar; 100 iterations = 0.000107, 1000 iterations = 0.001381, 2000 iterations = 0.022434.

    echo 'Foo', $bar; is the fastest on 100 and 1000 iterations, but for some reason it's slowest on 2000 iterations... ?

    0 讨论(0)
提交回复
热议问题