The time taken by your code depends on the way you coded the algorithm. Using built-in function might improve the performance. If you pasted samples of your algorithm would help in providing more specific advises.
The time taken depends upon the number of loops used in the code. Try to decrease the number of loops in the code. so if you doing any calculation element wise, try to avoid it and instead consider it as a set of 1D arrays . This is more generalized answer but it will depend on the objective of your code.