I have a 2d array of chars that I need to do some operations on. In some cases, I need to check if character is a-h. I used to accomplish this by checking if the character was not equal to any of the other characters (there are only 5 other characters). However, I recently had the idea that I could instead check if the character was < 'j' to get the same result with hopefully fewer assembly instructions.
In some places I put it, it did result in a small speed-up, but in others it resulted in a rather large slowdown. Any ideas why this is? What is the relative expense of != as opposed to < in if statements?
Here is an example code snippet:
if( arr[r][c] == arr[r][c+1] && arr[r][c] == arr[r][c+2]
&& arr[r][c] != 'q' && arr[r][c] != 'r' && arr[r][c] != 's' && arr[r][c] != 't')
vs
if( arr[r][c] == arr[r][c+1] && arr[r][c] == arr[r][c+2]
&& arr[r][c] < 'j')