Extremely long execution time |
[eluser]Unknown[/eluser]
I benchmarked this code and it takes ~25 seconds to execute There is a lot of data inside $kategorije array (it is a multi-leve array containing mysql query results (around 1000 rows of data total). In other parts of web application I handle a lot more data (10000+ rows) without problems... Could the nested foreach statements cause such a slowdown? I can't really see any other way to output data in this manner (hierarchy). Any ideas? Code: foreach($kategorije as $k) Thx in advance... Edit: I have just noticed something - variable $opasnost contains around ~25 000 rows... But again - ~25 seconds?
[eluser]stef25[/eluser]
Nested foreach will absolutely cause problems like this. I had the same problem on a site of mine. With 10 rows of test data I didn't notice it but with 300 rows of real data it took 5+ sec to load the page. And that was with only 2 levels of foreach, you have three. If the first array contains 1000 elements and the second one does too then you have 1000 x 1000 iterations = 1.000.000 loops. Add another 1000 in your third array and you have a billion iterations. Put a counter on it to make sure I'm not wrong. If you change your code to foreach($kategorije as $k) print_r($k) then I'm sure it will be less than a sec. Since you have no queries, it can not be much else than nested foreaches
[eluser]danmontgomery[/eluser]
http://ellislab.com/codeigniter/user-gui...hmark.html |
Welcome Guest, Not a member yet? Register Sign In |