简体   繁体   English

可能/不太可能而不是if / else

[英]likely/unlikely instead of if/else

I replaced one occurrence of if/else with likely/unlikely which given me some improvement in performance as this executes many times. 我用likely/unlikely替换了一次if/else ,这给了我一些性能上的改进,因为它执行了很多次。 Now I would like to change all the occurrences of if/else with likely/unlikely . 现在我想改变所有出现if/elselikely/unlikely I use this code on only one target/OS. 我只在一个目标/操作系统上使用此代码。

Does this have any drawbacks to replace all if/else 's ? 这有什么缺点来替换所有if/else的吗?

As likely and unlikely usually are macros defined in some library and expanding to some __buildin... -commands, the only drawback you can expect is, that this might be harder to read. 由于likely并且unlikely通常是某些库中定义的宏并扩展到某些__buildin...命令,因此您可以预期的唯一缺点是,这可能更难以阅读。

Edit: But please - use it only in that cases, where you really expect a condition to be more likely than the alternative! 编辑:但请 - 只在那种情况下使用它,你真的期望条件比替代品更可能!

If some platform / library does not implement likely and unlikely or the implementation is wrong, you can easily #define it empty by yourself. 如果某个平台/库没有实现likelyunlikely或实现错误,您可以轻松#define它自己空。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将表达式的仅一部分标记为“可能()/不太可能()”是否合理? - Is it reasonable to mark only part of an expression as likely()/unlikely() 学习可能()和不太可能()编译器提示的示例 - learning sample of likely() and unlikely() compiler hints Linux内核中可能存在的()/ unlikely()宏存在分段错误 - likely()/unlikely() macros in the Linux kernel with a segmentation fault 可能/不太可能的宏可用于用户空间代码吗? - Can likely/unlikely macros be used in user-space code? 是否有使用可能/不太可能提示的任何性能测试结果? - Are there any performance test results for usage of likely/unlikely hints? 使用__builtin_expect()时“非常有可能”或Linux内核的可能与不可能 - How much is “very likely” when using __builtin_expect() or Linux kernel's likely and unlikely 为什么不太可能和不太可能的宏对 ARM 汇编代码没有任何影响? - Why doesn't likely and unlikely macros have any effect on ARM assembly code? 如果和否则,我应该把更有可能的部分放在里面吗? - If and else, were should I put the more likely part? 在C if-else语句中,是否应该首先出现更可能的条件? - In the C if-else statement, should the condition which is more likely to be true come first? 使用 if else 语句代替 while - Using if else statements instead of while
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM