Will the comparison of two float numbers consume more CPU time than two ints?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
With today’s CPUs (excluding maybe embedded machines and the Atom) you can’t really make predictions on how fast a single inctruction in code may be.
First of all, it may be removed by the compiler if it’s known to be irrelevant, it may be rewritten by the compiler into something different which is known to be faster, etc. That’s one pitfall.
Secondly, CPUs can execute more than one instruction per cycle, or make them asynchronously and do other things while waiting for the FPU, etc.
In your specific case, comparing two numbers should be instant, i. e. in one cycle. But you probably can’t use that result in that very same cycle already. But this should hold true for both integers and floating-point numbers.
Remember that it’s just a series of bits and while floating-point numbers may be a little different due to their structure, it’s still a pretty easy problem (compare sign, compare exponent, compare mantissa).