Are there any performance differences between
float x, y;
// Set x and y
if(x > y)
{
// do something
}
and
float x,y;
// Set x and y
if(x.CompareTo(y) > 0)
{
// do something
}
Are they doing the same thing behind the scenes or is there more to it. I have a piece of performance critical code that does this comparison many, many times and I wanted to check that there wasn’t more going on than I thought.
The first one will be a little bit faster and a lot more readable.
x > ycompiles to an IL instruction that compares two values on the stack.x.CompareTo(y) > 0compiles to a normal method call followed by a comparison, which will be a little bit slower.