php 命名空间基准测试
使用命名空间会使网站更快还是更慢?这就是我想知道的。
如果它有助于提高网站性能,那么我想立即开始使用它。但如果它降低了它的性能,那么我根本不想使用它——即使是一点点性能也会对我的项目产生很大的影响。
有人有这方面的基准吗?您有何看法?
Does using namespaces make a site faster or slower? That's what I would like to know.
If it helps improving site performance, then i would like to start using it right now. But if it degrades it, then i don't want to use it at all - even a little performance makes big difference in my project.
Dos anyone have a benchmark on this? What are your views?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
PHP 命名空间在很大程度上(如果不是完全)与站点的性能无关。它们帮助您编写封装良好且结构化的代码 - 这就是为什么您不应该害怕使用它们,至少当您的项目达到一定的复杂性时。
如果您确实担心性能,您应该首先进行分析并检查真正的瓶颈所在。
PHP Namespaces are largely if not totally irrelevant for the performance of your site. They aid you at writing well-encapsulated and structured code - that's why you should not be afraid to use them, at least if your project reaches a certain complexity.
If you're really worried about performance, you should profile first and check where your real bottlenecks lie.
PHP 内部不存在命名空间,即使作为结构也是如此。在命名空间中定义的函数和类名称将只具有一个带有额外 ASCII 字符的标识符:
当 PHP 查找函数/类/常量名称时,它必须遍历与普通函数/类/常量相同的哈希表。由于它是一个哈希表,因此不会造成性能损失。
当然,解析是有区别的。但这是无法衡量的。
Namespace don't exist PHP-internally even as structure. Function and class names which are defined in a namespace will just have an identifier with an extra ASCII character within:
When PHP looks up a function/class/constant name, it has to traverse the same hash table as for ordinary functions/classes/constants. And since it is a hash-table, there is no performance penalty.
There is a difference for parsing, certainly. But it's not measurable.