I am in favor of using prewitt_x and prewitt_y to obtain the gradients in x- and y-direction. I also doubt that your implementation is faster...