++ x比x ++更优化??? [英] ++x is more optimised than x++ ???

查看:91
本文介绍了++ x比x ++更优化???的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一个很好的例子和信息,声称++ x已经优化了

而不是x ++。

是这样吗?


例如。

for(x = 0; x< 10; x ++)

有一个简单的解决方案,它会优化你的循环,(或者是
)(x = 0; x <10; ++ x)

它可以节省你的毫秒数代码轮换,对于像这样使用

循环的人来说,这是一种更快速的解析

数据的方法。

$ b $那是这样吗? ++ x如何比x ++更快?


Thx in advans,

Karthik Balaguru

解决方案

karthikbalaguru写道:


我遇到了一个很好的例子和信息声称++ x已经过优化

比x ++。

是这样吗?


例如。

for(x = 0 ; x< 10; x ++)

对此有一个简单的解决方法,它会优化你的循环,只需稍微支付


for(x = 0; x <10; ++ x)

它可以节省代码轮换的毫秒数,对于那些像这样使用

循环的人,这个通过你的
数据解析是一种更快的方法。


是这样吗? ++ x如何比x ++更快?


thx in advans,

Karthik Balaguru



理论上,++ c只增加c。 c ++递增c并返回

OLD值,因此必须保存旧值。


实际上大多数编译器没有任何区别。如果
旧值被丢弃,它们将保存

旧值,并生成与++ c相同的代码。


jacob navia写道:


karthikbalaguru写道:


> I我发现了一个很好的例子和信息,声称++ x比x ++更优化了。
是这样吗?

例如。
for(x = 0 ; x< 10; x ++)
有一个简单的解决方法,它会优化你的循环,所以稍微。
for(x = 0; x< 10; ++ x)
它可以节省代码轮换的毫秒数,对于那些像这样使用
循环的人来说,这是一种更快速地解析数据的方法。
<是这样吗? ++ x如何比x ++更快?

Thx in advans,
Karthik Balaguru



理论上, ++ c只增加c。 c ++递增c并返回

OLD值,因此必须保存旧值。


实际上大多数编译器没有任何区别。如果
旧值被丢弃,它们将保存

旧值,并生成与++ c相同的代码。



这需要一个不同的例子,以显示++ x on
CPU的优势,它在指令集中更好地支持它,像旧的PPC Macs。


" karthikbalaguru" < ka *************** @ gmail.com写信息

新闻:11 *************** *******@d55g2000hsg.googlegr oups.com ...


我遇到了一个很好的例子和信息声称++ x是

优于x ++。是这样吗?


例如。

for(x = 0; x< 10; x ++)

有这是一个简单的解决方案,它会优化你的循环,因此会稍微点亮。

for(x = 0; x< 10; ++ x)

它可以节省代码轮换的毫秒数,对于那些像这样使用

循环的人来说,这是一种更快速的解析

数据的方法。


是这样吗? ++ x如何比x ++更快?



几十年前,当编译器在优化方面非常糟糕时,很可能是b $ b。如今,他们应该编译成相同的指令,除非在

的情况下,表达式的结果值很重要。例如,y

= ++ x;可能仍然比y = x ++;更快,但两个陈述

不做同样的事情。


S


-

Stephen Sprunk上帝不玩骰子。 --Albert Einstein

CCIE#3723上帝是一个顽固的赌徒,他会在每一个可能的机会投掷
K5SSS骰子。 --Stephen Hawking

-

通过 http://www.teranews.com


I came across a nice example and info that claim that ++x is optimised
than x++.
Is it so ?

For example.
for(x = 0; x < 10; x++)
There is a simple fix for this, and it will optimize your loop, ever
so slightly.
for(x = 0; x < 10; ++x)
It can save milliseconds on your code rotations, for those using for
loops like this, this is a much faster way to parse through your
data.

Is it so ? How is it possible that ++x is faster than x++ ?

Thx in advans,
Karthik Balaguru

解决方案

karthikbalaguru wrote:

I came across a nice example and info that claim that ++x is optimised
than x++.
Is it so ?

For example.
for(x = 0; x < 10; x++)
There is a simple fix for this, and it will optimize your loop, ever
so slightly.
for(x = 0; x < 10; ++x)
It can save milliseconds on your code rotations, for those using for
loops like this, this is a much faster way to parse through your
data.

Is it so ? How is it possible that ++x is faster than x++ ?

Thx in advans,
Karthik Balaguru

In theory, ++c just increments c. c++ increments c and returns
the OLD value, so the old value must be saved.

In practice there isn''t any difference for most compilers. If
the old value is discarded, they throw the saving of the
old value away and generate the same code as for ++c.


jacob navia wrote:

karthikbalaguru wrote:

>I came across a nice example and info that claim that ++x is optimised
than x++.
Is it so ?

For example.
for(x = 0; x < 10; x++)
There is a simple fix for this, and it will optimize your loop, ever
so slightly.
for(x = 0; x < 10; ++x)
It can save milliseconds on your code rotations, for those using for
loops like this, this is a much faster way to parse through your
data.

Is it so ? How is it possible that ++x is faster than x++ ?

Thx in advans,
Karthik Balaguru


In theory, ++c just increments c. c++ increments c and returns
the OLD value, so the old value must be saved.

In practice there isn''t any difference for most compilers. If
the old value is discarded, they throw the saving of the
old value away and generate the same code as for ++c.

It would require a different example, to show an advantage for ++x on
CPUs which support it better in the instruction set, like old PPC Macs.


"karthikbalaguru" <ka***************@gmail.comwrote in message
news:11**********************@d55g2000hsg.googlegr oups.com...

I came across a nice example and info that claim that ++x is
optimised than x++. Is it so ?

For example.
for(x = 0; x < 10; x++)
There is a simple fix for this, and it will optimize your loop, ever
so slightly.
for(x = 0; x < 10; ++x)
It can save milliseconds on your code rotations, for those using for
loops like this, this is a much faster way to parse through your
data.

Is it so ? How is it possible that ++x is faster than x++ ?

Decades ago, when compilers were pretty bad at optimizing, that was likely
true. Nowadays, they should compile to identical instructions except in
cases where the resulting value of the expression matters. For instance, "y
= ++x;" is likely to still be faster than "y = x++;", but the two statements
don''t do the same thing.

S

--
Stephen Sprunk "God does not play dice." --Albert Einstein
CCIE #3723 "God is an inveterate gambler, and He throws the
K5SSS dice at every possible opportunity." --Stephen Hawking
--
Posted via a free Usenet account from http://www.teranews.com


这篇关于++ x比x ++更优化???的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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