| Trust no one, not even yourself: Profile your code. That said, if you aren't profiling already you are probably trolling us to get suggestion for your next blog article. ;-) As others have mentioned, use better algorithms i.e. it makes no sense to speed up a bubble sort routine instead of using a quick sort approach. A lot of speed improvements come from just not doing stuff in the first place vs. speeding up a naive or brute force approach. For example, suppose you want to determine when something enters the frame of a camera image that is 640x480 pixels big. The naive approach would be to compare every pixel of the frame to every pixel of the previous frame. The area of the frame is Width x Height: 307,200 pixels. A more efficient approach is to process just the edges (perimeter) of the image/frame since nothing can enter the frame without crossing the perimeter first. The perimeter is 2 x Width + 2 x Height: 1080 pixels. The 1st approach is 284 times slower (307,200/1080) and no amount of optimizing it is going to make it as fast as the 2nd approach. |