我++,I = I + 1和i + = 1哪一个是更快? [英] i++, i=i+1 and i+=1 which one is faster?
问题描述
我很好奇,想知道哪一个是在CPU中运行最快的I ++
, I + = 1
和 I = I + 1
,我怎么能衡量他们的执行时间?
I'm very curious to know which one is run fastest in the CPU among i++
, i+=1
and i=i+1
and how can I measure their execution time?
推荐答案
好了,起初人类发明了以下记录。
Well, at first the mankind invented the following record.
i = i+1;
然后在硬件个成就沿着mainkind发明了以下记录
then along with achievments in hardware the mainkind invented the following record
i += 1;
和在最后由于在计算机科学的进展人类发明以下记录
and at last due to the progress in the computer sciences the mankind invented the following records
++i;
和
i++;
所有这三种形式的记录是相同的一组的机器指令的前pressions(与++时,他们是一些比较复杂的前pression的部件i和i ++一个次要的例外):)而这组机器指令不会对编译器优化的水平,甚至依赖。)
All these three forms of records are expressions of the same set of machine instructions.(with a minor exception for ++i and i++ when they are parts of some more complex expression):) And this set of machine instructions does not depend even on the level of the compiler optimization.:)
P.S。当然,我们正在讨论这些运营商为基本类型。没有任何意义,讨论这些运营商为用户定义的类型,因为它们可以以各种方式被重载。
P.S. Of course we are discussing these operators for fundamentals types. There is no any sense to discuss these operators for user-defined types because they can be overloaded in various ways.
这篇关于我++,I = I + 1和i + = 1哪一个是更快?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!