# Which math operator is faster?

Which line should process faster and why?

``````if (x == y) { }
``````
OR
``````if (x > y) { }
``````
OR
``````if (x < y) { }
``````
OR
``````if (x >= y) { }
``````

Which operator should process faster (+, -, * or /)?
LVL 12
###### Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Fixer of ProblemsCommented:
The 'if' lines should all be the same because subtraction is normally used and the results are used to determine the response.  The first checks for a 0 result, the second checks for a positive result, negative result, and positive or 0 result.

For the operators, + and - are the fastest for integers because they are a single step operation, * and / are multiple steps.  For floating point, they are all multiple steps.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Software EngineerAuthor Commented:
Can you give me an example on how the computer process +, -, *, and /?

I want detailed information.

Thanks,
CIOCommented:
You've got it:

http://msdn.microsoft.com/en-us/library/aa309387(v=vs.71).aspx

That's for .Net 1.1. For 4.0 it is comes with the Microsoft Windows SDK Tools and is typically located in:

C:\Program Files\Microsoft SDKs\Windows\v7.0A\bin\NETFX 4.0 Tools\ildasm.exe

/gustav
Fixer of ProblemsCommented:
For integers and characters that fit in the main CPU registers (32 or 64 bit), + and - can simply be done in a single step by the main ALU.  All other operations are passed to the math coprocessor.  This page http://www.top500.org/2007_overview_recent_supercomputers/intel_xeon gives a good example of the blocks in an Intel CPU.  An earlier CPU would be easier to understand since there isn't as much detail.  Here's one http://www.laynetworks.com/Block%20diagram%20of%20the%20Pentium.htm of an early Pentium CPU.   But they keep adding things to speed up the instructions.  Now all of this is hidden from you by the C# compiler and the .NET framework.  The compiler determines what kind of data you are using and selects the appropriate .NET CLR routines to process it.
###### It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.