The best thing to do is to do some performance profiling. Check out some of these nodes on profiling:
Re: Improving the efficiency of code when processed against large amount of data or
performance profiling. In these nodes there are discussions on profiling your code line by line. Figure out which line takes the longest to process and try and bring down that time.