Performance of == vs Equals in generic C# class
|Added at||2016-12-30 00:12|
For some reason C# does not allow == operator use in generic classes like here:
If I replace == with val.Equals(value) I have code that works as expected but if I look at bytecode it looks much more complicated. A very simple test comparing int variables in the loop using == and Equals() showed that Equals() version was two times slower than "==" version.
I wonder if there is a way to compare primitive value types in generic classes that would be as fast as == operator. Any ideas welcome.
Edit: I got lost between timers. Performance difference is not as dramatic. Here are my latest results:
In short: Equals() is good enough.