tonyg #1 If P is always between 1-6 then that piece of code is unlikely to be causing any performance problems. What each of the functions do might cause a problem which is why you need to profile them.