$ start = microtime ( true ) ;
$ res1 = array ( ) ;
for ( $ i = 0 ; $ i < 1000 ; $ i ++ ) {
$ res1 = array_merge ( $ res1 , array ( 1 , 2 , 3 ) ) ;
}
echo "1000 merges:" . ceil ( ( microtime ( true ) - $ start ) * 1000 ) . "ms \ n " ;
')
$ start = microtime ( true ) ;
$ toMerge = array ( ) ;
for ( $ i = 0 ; $ i < 1000 ; $ i ++ ) {
$ toMerge [ ] = array ( 1 , 2 , 3 ) ;
}
$ res2 = call_user_func_array ( 'array_merge' , $ toMerge ) ;
echo "call_user_func_array ('array_merge', ..):" . ceil ( ( microtime ( true ) - $ start ) * 1000 ) . "ms \ n " ;
echo "It is true that the two arrays are equal? It is" ;
var_export ( $ res2 === $ res1 ) ;
echo ". \ n " ;
~ % php ~/tmp/array_merge.php
1000 merges: 980ms
call_user_func_array('array_merge',..): 11ms
Is it true that the two arrays are equal? It is true.
Source: https://habr.com/ru/post/101608/
All Articles