Buda Gavril
Buda Gavril

Reputation: 21657

Time-consuming operation

if I have two integer variables with allocated memory and value a and b, which is the more time consuming (time of execution by the processor) operation: comparison (a == b) or assignment (a = b) ? And why?

Upvotes: 1

Views: 1235

Answers (2)

Ingo
Ingo

Reputation: 36349

Because the assignment involves a memory write (assuming that a is not a local value held in a register), chances are that it is slower on contemporary processors.

Upvotes: 0

MattBianco
MattBianco

Reputation: 1531

It probably depends on your processor architecture and the resulting binary executable.

Upvotes: 1

Related Questions