Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php namespace benchmark

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?

like image 565
Basit Avatar asked Mar 16 '11 20:03

Basit


2 Answers

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.

like image 70
Alexander Gessler Avatar answered Sep 19 '22 21:09

Alexander Gessler


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:

[1] => "namespace\user_func",    // get_defined_functions()

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.

like image 26
mario Avatar answered Sep 19 '22 21:09

mario