在索引名称周围不使用单引号是否会明显/显着地减慢执行速度?
如果我要说
echo $arr[some_index];
而不是说
echo $arr['some_index'];
错误通知会导致大量处理器时间/功率损失吗?我知道这不是正确的语法,但是在我正在从事的项目中已经有大量这样编写的代码。
If I were to say
echo $arr[some_index];
as opposed to saying
echo $arr['some_index'];
Will there be a significant amount of processor time/power lost to the error notice? I am aware that it is not proper syntax, but there is a huge amount of code written like this already on a project I am working on.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
嗯,检查起来很简单。您可以检查任何语句的执行时间,如下所示:
为您想要测试的每种类型执行其中一项。自然,无论哪个始终最快,都将是最快的。
您还可以使用
memory_get_usage
来确定每次调用之前和之后使用了多少内存。现在,您还应该收到大量
通知
。如果未定义常量,则会将其视为字符串,但会引发通知。另一个问题是,如果您的密钥与常量发生冲突,您将检查错误的值。这确实不是一个好的做法。我会检查并更换所有东西。Well, it's simple enough to check. You can check the execution time on any statement(s) like such:
Do one of those for each type you'd like to test. Whichever is consistently fastest will be the quickest, naturally.
You can also use
memory_get_usage
to determine how much memory has been used, before and after each call.Now, you should also be getting a large number of
NOTICE
's. If a constant isn't defined, it's treated as a string instead, but throws a notice. Another problem is if your key ever conflicts with a constant, you'll be checking the wrong value. It's really just not good practice. I'd go through and replace everything.我认为对性能的影响可以忽略不计,但是我的纯粹主义者希望看到一致使用引号/不引号。
I think the performance impact would be negligible, however the purist in me would want to see consistent use of quotes/no quotes.