php单引号和双引号的速度,在php中单引号和双引号是否有性能优势?[复制]

应该注意的是,当使用亚当·赖特的3个变量的例子的修改版本时,结果是相反的,前两个函数实际上更快,一致。这是在CLI上使用PHP 7.1:

function timeFunc($function, $runs)

{

$times = array();

for ($i = 0; $i < $runs; $i++)

{

$time = microtime();

call_user_func($function);

@$times[$i] = microtime() - $time;

}

return array_sum($times) / $runs;

}

function Method1()

{

$foo = 'some words';

$bar = 'other words';

$bas = 3;

for ($i = 0; $i < 10000; $i++)

$t = "these are $foo, $bar and $bas";

}

function Method2()

{

$foo = 'some words';

$bar = 'other words';

$bas = 3;

for ($i = 0; $i < 10000; $i++)

$t = "these are {$foo}, {$bar} and {$bas}";

}

function Method3()

{

$foo = 'some words';

$bar = 'other words';

$bas = 3;

for ($i = 0; $i < 10000; $i++)

$t = "these are " . $foo . ", " . $bar . " and " .$bas;

}

print timeFunc('Method1', 10) . "\n";

print timeFunc('Method2', 10) . "\n";

print timeFunc('Method3', 10) . "\n";

我也试过用'3'代替整数3,但是我得到了同样的结果。

$bas=3时:

0.0016254

0.0015719

0.0019806

0.0016495

0.0015608

0.0022755

值得注意的是,这些结果变化很大(我得到大约300%的变化),但平均值似乎相对稳定,几乎(10个案例中有9个)总是显示第一个2个方法的执行速度更快,方法2总是比方法1稍快。

总之:对于一个单独的操作(无论是插值还是级联)来说,对于组合操作来说并不总是正确的。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值