(一般查询)为什么n ++执行速度比n + 1快 [英] (General Query) why n++ executes faster than n+1

查看:87
本文介绍了(一般查询)为什么n ++执行速度比n + 1快的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



为什么n ++的执行速度比n + 1还要快......还是realli执行得更快?


谢谢

Venugopal.B

Hi,
why n++ executes faster than n+1..... or does it realli execute faster?

thanks
Venugopal.B

推荐答案

VenuGopal< Ve ******* @ discussion.microsoft.com>写道:
VenuGopal <Ve*******@discussions.microsoft.com> wrote:
为什么n ++执行速度比n + 1还要快......还是realli执行得更快?
why n++ executes faster than n+1..... or does it realli execute faster?




我想你的意思是问:


|如果n是int,那么

| n ++;

|执行速度比

|快n = n + 1;

| ?


上面的答案是:不。两个语句都编译成确切的

相同的IL指令。



I assume that you mean to ask:

| If n is an int, does
| n++;
| execute faster than
| n = n + 1;
| ?

The answer to the above is: no. Both statements compile down to the exact
same IL instructions.


n ++只是更快地输入...

- -

David Anton
www.tangiblesoftwaresolutions.com

主页:

清除VB:清理过时的VB.NET代码

即时C#:从VB.NET转换为C#

即时VB:从C#转换为VB.NET

即时J#:从VB.NET转换为J#

" VenuGopal"写道:
n++ just types faster...
--
David Anton
www.tangiblesoftwaresolutions.com
Home of:
Clear VB: Cleans up outdated VB.NET code
Instant C#: Converts from VB.NET to C#
Instant VB: Converts from C# to VB.NET
Instant J#: Converts from VB.NET to J#
"VenuGopal" wrote:

为什么n ++执行速度比n + 1还要快.....还是realli执行得更快?

感谢< Venugopal.B
Hi,
why n++ executes faster than n+1..... or does it realli execute faster?

thanks
Venugopal.B



我听过面试问题,为什么++ n的执行速度比n ++更快?
? br />
前缀运算符总是比后缀更快。后缀

版本涉及对前缀的复制和内部调用。对于简单的

类型,两者之间的相对成本应该很小。对于更多

复杂对象(例如迭代向量),成本可能会大于b
。 C ++文献中的普遍共识(更多例外C ++,更多有效的C ++)是前缀版本应始终是优先的b / b
。这样做你不会出错。另外,写++

而不是++不需要任何费用。

I have heard interview questions about why would ++n executes faster
than n++?
The prefix operator will always be faster than the postfix. The postfix
version involves a copy and internal call to the prefix. For simple
types the relative cost between the two should be small. For more
complicated objects (e.g. iterating over a vector) the cost may be
larger. The general consensus in C++ literature (More Exceptional C++,
More Effective C++) is that the prefix version should always be
preferred. Doing this you cannot go wrong. In addition, writing ++
instead of ++ costs nothing.


这篇关于(一般查询)为什么n ++执行速度比n + 1快的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆