A simple technique to find the time taken to execute a piece of code is to toggle a pin and measure the pulse width using an oscilloscope. The code used to toggle pin takes some time to execute. To reduce that time, use techniques given in AN60630