array_push and $ arr [] = $ v performance testing using Note

array_push and $ arr [] = $ v are appended to the end of the array element. The difference is that the former may be a push multiple elements.
Test environment: phpstudy integrated environment: apache2.4 + php 7.2 version
1, array_push pressed into 2,000,000 (two million) elements.
<ignore_js_op>
FIG Effect: <ignore_js_op>
2, using the $ arr [] = $ v pressed embodiment 2000000 (two million) elements.
<ignore_js_op>
The effect is as follows:
<ignore_js_op>
Each element of a press-fitting, using the $ arr [] = $ v array_push embodiment faster than using the method.
3, using a plurality of elements array_push pressed once, repeated use than $ arr [] = $ v pressed fast. array_push pressed once more elements, the higher efficiency.
<ignore_js_op>
The effect is as follows:
<ignore_js_op>
Test Summary:
If it is pressed into an element, use the $ arr [] = $ v high efficiency, because you can save an additional burden on the calling function. If the plurality of elements simultaneously pressed, array_push use high efficiency, because there is no repetition get a pointer to the end of the file. When a one-time service requirements can be pressed into a plurality of element selected array_push, contrary to select $ arr [] = $ v

 More technical information may concern: gzitcast

Guess you like

Origin www.cnblogs.com/heimaguangzhou/p/11446922.html