Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which operator is faster: != or >

Tags:

c++

c

Which operator is faster: > or ==?

Example: I want to test a value (which can have a positive value or -1) against -1 :

if(time > -1)
// or
if (time != -1)

time has type "int"

like image 233
Aminos Avatar asked Nov 28 '22 03:11

Aminos


1 Answers

The standard doesn't say. So it's up to what opcodes the given compiler generates in its given version, and how fast a given CPU executes them.

I.e., implementation / platform defined.

You can find out for a specific compiler / platform combination by looking at / benchmarking the executable code.

But I seriously doubt it will make much of a difference; this is the kind of micro-optimization that is almost always dwarfed by higher-level architectural decisions.

like image 113
DevSolar Avatar answered Dec 08 '22 12:12

DevSolar