I have a piece of code that's like
if (A == B)
{
...
}
else if (A < B)
{
...
}
else // (A > B)
{
...
}
I realize there is a redundancy problem because there will be some of the same bit comparisons going into the computation of == and <. How can I optimize my code to make it fancier and faster?
For C# you could use a generic function that takes in the 2 values, and then a lambda action for each case.
Then you can re-use it as much as you wanted like so:
I can't say I'd recommend doing this, but it'd work. It's no faster (prob slower), but I suppose one could say that it's "fancier."