php会在没有警告的情况下运行得更快吗? [英] Does php run faster without warnings?
问题描述
由于PHP代码即使在警告和注意未定义索引和非静态方法被称为静态等问题的情况下也能正常运行,所以问题是,如果我花时间删除我的所有注意事项和警告,代码会以更快的速度运行吗?
Since PHP code will run just fine even if it's riddled with warnings and notices about undefined indexes and non-static methods being called as static, etc, the question is, if I spend the time to remove ALL notices and warnings from my code will it run significantly faster?
推荐答案
我收藏了一篇文章,其中作者为此做了一些基准测试;不幸的是,它是法语的...但是这里是(也许您会理解其中的某些部分):
I bookmarked an article in which the author did some benchmarks about that ; unfortunatly, it's in french... but here it is (maybe you'll understand some parts of it) : Ne faites pas d'erreur
以下是数字,以帮助不懂法语的人:
And here are the numbers, to help people who don't read french :
- 10k通知,启用了
error_reporting
和display_errors
:5,162.76 ms - 相同,但禁用了
display_errors
:136.18 ms - 相同,但也禁用了
error_reporting
:117.79 ms - 最后,在修补代码之后,它不再发出任何通知:19.51 ms
- 10k notices, with
error_reporting
anddisplay_errors
enabled : 5,162.76 ms - same, but with
display_errors
disabled : 136.18 ms - same, but with
error_reporting
disabled too : 117.79 ms - and, finally, after patching the code so it doesn't produce any notice anymore : 19.51 ms
这意味着,是的,即使未显示或未报告通知/警告/错误,PHP代码也可以更快地运行.
Which means that, yes, PHP code runs faster without notices/warnings/errors, even when those are not displayed nor reported.
Derick Rethans在本文中说了同样的话:应避免使用闭门运算符(@)的五个原因 (引用):
Derick Rethans says the same thing in this article : Five reasons why the shut-op operator (@) should be avoided (quoting) :
原因3:速度很慢(第2部分)
每当PHP产生错误时
内部消息,它被处理,
一直格式化到完全
格式化的消息可以是
直接输出到浏览器.
仅在显示之前
error_reporting
设置被检查.
但是,这与
@-运算符.
错误
消息始终是完全格式化的
在检查error_reporting
之前-或
display_errors
.
Whenever PHP generates an error
message internally, it's processed and
formatted all the way up to the fully
formatted message that can be
outputted straight to the browser.
Only just before it is displayed the
error_reporting
setting is checked.
This however, is not related to the
@-operator exclusively.
The error
message is just always fully formatted
before error_reporting
is checked—or
display_errors
for that matter.
这篇关于php会在没有警告的情况下运行得更快吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!