PHP functions and the use of pseudo-functions: Will long function names affect performance?

WBOY
Release: 2016-07-29 09:01:16
Original
1020 people have browsed it

Long function names will affect performance
For the use of php functions, there are some suggestions as follows
1. A function can be completed with a built-in function, try to use it instead of writing the php function yourself.
2. If a certain function has high performance requirements, you can consider using extensions to implement it.
3. Php function calls are expensive, so don't over-encapsulate them. Some functions, if they need to be called a lot of times, will not work
It can be implemented with only 1 or 2 lines of code. It is recommended not to encapsulate the call.
4. Don't be overly obsessed with various design patterns. As described in the previous article, excessive encapsulation will cause performance degradation. There are trade-offs between the two that need to be considered.
Php has its own characteristics, and you must not imitate the Java model too much.
5. Functions should not be nested too deeply, and recursion should be used with caution.
6. Pseudo functions have high performance and will be given priority when implementing the same functions. For example, use isset instead of array_key_exists
7. Returning a reference from a function does not make much sense and has no practical effect. It is recommended not to consider it.
8. Class member methods are no less efficient than ordinary functions, so there is no need to worry about performance loss. It is recommended to consider more static methods, which have better readability and security.
9. Unless there are special needs, it is recommended to use pass-by-value rather than pass-by-reference when passing parameters. Of course, if the parameter is a large array and needs to be modified, you can consider passing it by reference.

Pseudo functions and their performance
In php, there are some functions that are standard function usage, but the underlying implementation is completely different from the real function call. These functions
It does not belong to any of the three functions mentioned above. Its essence is a separate opcode, which is called a pseudo function or instruction function here.
As mentioned above, pseudo functions are used just like standard functions and appear to have the same characteristics. But when they were finally executed, they were zend
It is reflected as a corresponding instruction (opcode) to call, so its implementation is closer to operations such as if, for, and arithmetic operations.
Pseudo functions in php

<code><span>isset</span><span>empty</span><span>unset</span><span>eval</span></code>
Copy after login

As can be seen from the above introduction, since pseudo functions are directly translated into instructions for execution, compared with ordinary functions, there is less overhead caused by a function call,
So the performance will be better. We make a comparison through the following test. Both Array_key_exists and isset can determine a key in the array
If they exist, take a look at their performance
As can be seen from the figure, compared with array_key_exists, isset performance is much higher, basically about 4 times that of the former, and even with empty function calls
In comparison, its performance is about 1 times higher. This also proves that the overhead of PHP function calls is still relatively large.

http://txjia.com/tip/?2013-1K-BPEG

').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });

The above introduces the use of PHP functions and pseudo functions: Will long function names affect performance? , including relevant content, I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template