In my experience, whenever it's a matter of some code taking 10x the time I thought it would take, there are only two culprits:
Hardware bottlenecks are thankfully pretty easy to measure: tools like top or PerfMon can show you if you're paging unexpectedly high amounts to RAM or the network.
For your algorithm, review the contents of every loop in your code to see if there's something that's going to be O(n) when you initially thought it was O(1). In a loop, that becomes O(n*m) instead of the O(m) you expect of a loop.
After understanding your algorithm's order of work or complexity, it's time to reduce each iteration. If anything is O(n) and called twice, ask yourself why. If you're passing big data by value instead of reference, ask yourself why.
As a last tip, consider doing your benchmarking work outside the extra overhead of the web server and/or database, if possible. It can open your investigation to the use of more tools, more iterations, and more focus on your part. It will be good for your code to be decoupled from those system dependencies, regardless.
--
[ e d @ h a l l e y . c c ]
In reply to Re: Why can code be so slow?
by halley
in thread Why can code be so slow?
by freakingwildchild
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |