I've got a speed critical piece of code which involves the comparison of 2 4 byte arrays. I've been trying to work out the fastest way to achieve this, and have looked at this.
Doing 100,000,000 comparisons using pinvoke and memcmp takes ~9.5 seconds, using the UnsafeCompare method posted in the above link takes ~3.5 seconds.
If set 2 4 character strings and compare those using s1 == s2 it takes ~0.5 seconds. If I use string.Compare(s1, s2) it takes about ~12 seconds.
Is there some way I can get my byte array comparisons to compare is speed to doing s1 == s2? And if not, could there be any problems with me doing something like below, basically storing my byte arrays as strings?
string s1 = Convert.ToChar(1).ToString() + Convert.ToChar(2).ToString() + Convert.ToChar(3).ToString() + Convert.ToChar(4).ToString();
string s2 = Convert.ToChar(1).ToString() + Convert.ToChar(2).ToString() + Convert.ToChar(3).ToString() + Convert.ToChar(4).ToString();
if (s1 == s2)
.....
Hoping someone can help me out with this. Thanks!