Finding program bottlenecks
The best way to find out why a program is slow (and also, to optimize an already fast-running program), is to use the profiler.
This tool is included in the runtime system, and generates a report that shows what function in your program is the most time-consuming.
Additionally, you might want to identify part of code of your programs that are never executed, or executed very often, by using the coverage tool.