My problems with the invert() function has been resolved. I found that somewhere in my program it was trying to invert . So I just added a conditional statement ahead of it. Evidently the C program did the same sort of thing. So now I've shaved another 20% of execution time off of my program!