<?php 和 ?>标签影响性能? [英] Does the quantity of <?php and ?> tags affect performance?

查看:51
本文介绍了<?php 和 ?>标签影响性能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 php 文件中,我想知道开始和结束标记是否会影响性能.

In my php files, I wonder if the opening and closing tags have a performance impact.

即.

<?php echo 'Hello world'; ?>
<?php echo 'Hello world'; ?>
<?php echo 'Hello world'; ?>
<?php echo 'Hello world'; ?>
<?php echo 'Hello world'; ?>

对比

<?php
  echo 'Hello world';
  echo 'Hello world';
  echo 'Hello world';
  echo 'Hello world';
  echo 'Hello world';
?>

如果有,有什么影响?

推荐答案

它对性能有影响吗?是的.仅仅是因为解析器要解析的文本更多.一定有影响.是的,它会产生可衡量的影响.

Does it have a performance impact? Yes. Simply because there is more text for the parser to parse. It must have an impact. And yes, it will have a measurable impact.

它是否产生了有意义的影响?一点都不.即使您的应用程序中有数百万个差异,您也很难看到任何差异.是的,会使用更多的时钟周期,但微不足道...

Does it have a meaningful impact? No. Not at all. You would be hard pressed to see any difference even if you had millions of them in your app. Yes, there will be more clock cycles used, but trivially...

更重要的是要注意这两段代码通常并不相同.PHP 将在结束 ?> 后删除一个新行,但 ?> 之后的任何其他字符将在输出中呈现.所以 ?> 之后的尾随空格或多个换行符将被直接渲染.

The bigger thing is to note that the two pieces of code are not identical in general. PHP will strip a single new line after a closing ?>, but any other characters after ?> will render in the output. So trailing spaces or multiple newlines after ?> will be rendered directly.

所以我的建议是忽略性能,编写正确且更具可读性的代码(语义更正确的代码).并忽略小的性能差异...

So my suggestion is ignore the performance, write the correct and more readable code (the more semantically correct code). And ignore small performance differences...

这篇关于&lt;?php 和 ?&gt;标签影响性能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆