Speed difference between If-Else and Ternary operator in C…?

后端 未结 6 2324
别跟我提以往
别跟我提以往 2020-12-01 16:49

So at the suggestion of a colleague, I just tested the speed difference between the ternary operator and the equivalent If-Else block... and it seems that the ternary operat

6条回答
  •  长情又很酷
    2020-12-01 17:45

    You could also go completely branchless and measure if it makes any difference:

    int m = -(i & 1);
    a = (b & m) | (c & ~m);
    

    On today's architectures, this style of programming has grown a bit out of fashion.

提交回复
热议问题