Is there any performance difference between greater than and greater than or equal?

前端 未结 3 357
感情败类
感情败类 2021-01-17 14:33

On today\'s modern processors, is there any performance difference between greater than and greater than or equal comparison for a branch condition? If I have a condition t

3条回答
  •  醉梦人生
    2021-01-17 15:01

    I'm not quite sure how the underlying implementation is done in the ALU/FPU but there should only be one operation for all of them (on primitive types that is)

    I really hope that this is only a question because you are curious and not that you're trying to optimize, this will never give you a big performance boost and most likely your code will contain far far worse performance issues.

    You can event implement all relation operators using just one:

    a < b is the base
    a > b == b < a
    a >= b == !(a < b)
    a <= b == !(a > b)
    

    This is of course not how it's implemented in the CPU, this is more trivia.

提交回复
热议问题