PHP and Recursion
| From: | Brian Moon | Date: | Fri, 24 Feb 2006 22:05:29 +0000 |
| Subject: | PHP and Recursion | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-22009@lists.php.net to get a copy of this message | ||
Hi guys,
I am working on script that will assemble data to create a page and have come to an interesting conclusion. Its a perfect fit for recursion as part 1 of the doc will require additional parts and so on.
I wrote it at first with two loops. The first loop gathered data and the second arranged the data.
For completeness sake, I rewrote it using recursion where I have a get_data() function that is called within itself if said data needs more data.
The results were quite suprising. I get about a 80% increase in speed (using openload with 20 concurrents to test) using the recursion. Now, at most, I will be recursing 4 or 5 levels deep.
Does PHP optimize recursion in such a way that this is expected or did I get lucky and I may hit a wall when I am not looking?
--
Brian Moon
dealnews.com
--------------
How to go broke saving money.
http://dealnews.com/