Which “if” construct is faster - statement or ternary operator?

前端 未结 6 680
借酒劲吻你
借酒劲吻你 2020-12-01 01:08

There are two types of if statements in java - classic: if {} else {} and shorthand: exp ? value1 : value2. Is one faster than the oth

6条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-01 01:30

    These are the same. Both of them are fairly fast, typically around 10-30 nano-seconds. (depending on usage pattern) Is this time frame important to you?

    You should do what you believe is clearest.

提交回复
热议问题