Do you think operator < is faster than <= in C/C++?


No, the operator < takes same time to execute as operator <= takes. Both operators execute similarly and take same execution time to perform the execution of instructions.

There is a jcc( jump instruction) at the time of compilation and depending upon the type of comparison, it jumps to the instructions. The following are some of the comparison type −

  • je − Jump if equal

  • jg − Jump if greater

  • jne − Jump if not equal

  • jge − Jump if greater or equal

There is only one difference between operator < and operator <= that the operator < executes ‘jg’ instruction while the operator <= executes ‘jge’ instruction. But both operators take same time to execute.

Here is an example of operator < and <= in C language,

Example

 Live Demo

#include<stdio.h>
int main() {
   int a = 8;
   int b = 8;

   if(a<b)
   printf("b is greater than a\n");

   if(a<=b)
   printf("b is greater or equal to a");
   else
   printf("b is smaller than a");
   return 0;
}

Output

Here is the output

b is greater or equal to a

Updated on: 25-Jun-2020

838 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements