Is quot;for(;;)quot; faster than quot;while (true)quot;? If not, why do people use it?(是“for(;;)比“while(真)快?如果不是,人们为什么要使用它?)
问题描述
for (;;) {
//Something to be done repeatedly
}
我见过这种东西用得很多,但我觉得它很奇怪......说 while(true) 或类似的东西不是更清楚吗?
I have seen this sort of thing used a lot, but I think it is rather strange...
Wouldn't it be much clearer to say while(true), or something along those lines?
我猜(这是许多程序员求助于神秘代码的原因)这会快一点点?
I'm guessing that (as is the reason for many-a-programmer to resort to cryptic code) this is a tiny margin faster?
为什么,它真的值得吗?如果是这样,为什么不这样定义:
Why, and is it really worth it? If so, why not just define it this way:
#define while(true) for(;;)
另见:哪个更快:while(1) 还是 while(2)?
推荐答案
- 并没有更快.
- 如果您真的很在意,请使用适用于您平台的汇编器输出进行编译,然后看看.
- 没关系.这从来都不重要.随心所欲地编写无限循环.
这篇关于是“for(;;)"比“while(真)"快?如果不是,人们为什么要使用它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:是“for(;;)"比“while(真)"快?如果不是,人们为什么要使用它?
基础教程推荐
- 随机插入/删除的综合向量与链表基准 2022-01-01
- 提升 ASIO 流缓冲 2021-01-01
- 如何部分禁用 cmake C/C++ 自定义编译器检查 2021-01-01
- 如何更改 SysDateTimePick32 或 CDateTimeCtrl 的背景颜色? 2022-01-01
- 将不可复制的闭包对象传递给 std::function 参数 2021-01-01
- 如何在 C++ 中正确使用命名空间? 2022-01-01
- 与 CAS 的原子交换(使用 gcc 同步内置函数) 2022-01-01
- c++ STL设置差异 2022-01-01
- C++:获取传递给函数的多维数组的行大小 2021-01-01
- 为什么我们不能使用“虚拟继承"?在 COM 中? 2022-01-01
