I have a script that is using too much cpu cycles, i was wondering how i can fix this, and maybe speed up the script a bit.
Here's the basic five step plan for dealing with Performance issues:
- Find out where your script is spending most of its time (via profiling, putting in code to record timestamps, whatever). Go there.
- Look for work that you don't need to do, and don't do it.
- Look for work that only needs to be done once, rather than over and over and over. Do that work once.
- Look for less (time) expensive ways of doing whatever work is left over.
- Repeat steps 1-4 until performance is good enough.
Conceptually, that's it.