(一般查询)为什么n ++执行速度比n + 1快

编程入门 行业动态 更新时间:2024-10-09 07:27:44
本文介绍了(一般查询)为什么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>写道: VenuGopal <Ve*******@discussions.microsoft> 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 主页: 清除VB:清理过时的VB.NET代码 即时C#:从VB.NET转换为C# 即时VB:从C#转换为VB.NET 即时J#:从VB.NET转换为J# " VenuGopal"写道: n++ just types faster... -- David Anton www.tangiblesoftwaresolutions 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快

本文发布于:2023-11-27 18:04:57,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1639037.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:速度

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!