Should explore how to improve the efficiency of PHP recursive



We are in the actual programming code, you will find PHP recursion is very low efficiency, for programmers, they have to deal with PHP recursive well.In this paper, we specifically told you all about PHP recursive efficiency, in the hope of another friend in need help.

Recently wrote a quick sort algorithm, the efficiency that can not be recursive PHP, across the board, in a variety of servers, the performance may be different.
function qsort (& $ arr) {_quick_sort ($ arr, 0, count ($ arr) - 1);} / bin / boot / dev / etc / home / lib / lost + found / media / misc / mnt / net/ opt / proc / root / sbin / selinux / srv / sys / tmp / u01 / usr / var / vmware backup bin conf config data eshow_sitemap.html generate.sh log maint sitemap.html svn tmp quick sort algorithm using recursion.backup bin conf config data eshow_sitemap.html generate.sh log maint sitemap.html svn tmp backup bin conf config data eshow_sitemap.html generate.sh log maint sitemap.html svn tmp @ param array $ arr the array to sort backup bin conf config dataeshow_sitemap.html generate.sh log maint sitemap.html svn tmp @ param int $ low lowest ranking sub-section backup bin conf config data eshow_sitemap.html generate.sh log maint sitemap.html svn tmp @ param int $ high ranking highest in the wordSection backup / bin / conf / data / log / maint / svn / tmp / function _quick_sort (& $ arr, $ low, $ high) {$ low_data = $ arr [$ low]; $ prev_low = $ low; $ prev_high= $ high; while ($ low <$ high) {while ($ arr [$ high]> = $ low_data & & $ low <$ high) {$ high -;} if ($ low <; $ high) {$ arr [$ low] = $ arr [$ high]; $ low + +;} while ($ arr [$ low] <= $ low_data & & $ low <$ high) {$ low + +;} if ($ low <$ high) {$ arr [$ high] = $ arr [$ low]; $ high -;}} $ arr [$ low] = $ low_data; if ($ prev_low <$low) {_quick_sort ($ arr, $ prev_low, $ low);} if ($ low + 1 <$ prev_high) {_quick_sort ($ arr, $ low + 1, $ prev_high);}} function quick_sort (& $arr) {$ stack = array (); array_push ($ stack, 0); array_push ($ stack, count ($ arr) -1); while (! empty ($ stack)) {$ high = array_pop ($ stack); $ low = array_pop ($ stack); $ low_data = $ arr [$ low]; $ prev_low = $ low; $ prev_high = $ high; while ($ low <$ high) {while ($ arr [$ high]> = $ low_data & & $ low <$ high) {$ high -;} if ($ low <$ high) {$ arr [$ low] = $ arr [$ high]; $ low + +;} while ($ arr [$ low] <= $ low_data & & $ low <$ high) {$ low + +;} if ($ low <$ high) {$ arr [$ high] = $ arr [$ low]; $ high -;}} $ arr [$ low] = $ low_data; if ($ prev_low <$ low) {array_push ($ stack, $ prev_low); array_push ($ stack, $ low);}if ($ low + 1 <$ prev_high) {array_push ($ stack, $ low + 1); array_push ($ stack, $ prev_high);}}}


The following is the efficiency of testing the speed of the recursive PHP Code:




function qsort_test1 () {$ arr = range (1, 1000); shuffle ($ arr); $ arr2 = $ arr; $ t1 = microtime (true); quick_sort ($ arr2); $ t2 = microtime (true) - $t1; echo "non-recursive call cost:". $ t2. "
"; $ Arr1 = $ arr; $ t1 = microtime (true); qsort ($ arr1); $ t2 = microtime (true) - $ t1; echo" recursive call cost: ". $ T2."
";}






In my IIS server (CGI) mode, the efficiency of my PHP recursive test results are:



The cost of non-recursive call: 0.036401009559631
Recursive call cost: 0.053439617156982



In my Apache server, my test result:



The cost of non-recursive call: 0.022789001464844
Recursive call cost: 0.014809131622314

PHP recursive results efficiency of the opposite, while the PHP version is the same.

The efficiency of PHP seems to be a recursive analysis of specific issues.