in reply to improving the speed

...my hash is like this ... currently it takes a long time to calculate the $MI_

You really should post a complete program which demonstrates exactly that :) How do I post a question effectively?